? I load this page: function loadGUIComponents() { // load conte...">

JQuery loading doesn't seem to be handling <script type = ".." src = "a.js">?

I load this page:

 function loadGUIComponents() {
// load contents into each accordion area
$("#listEntryDiv").load("listEntry/listEntryIndex.html");
$("#openEntryDiv").load("openEntry/openEntryIndex.html");
 };

In listEntryIndex.html, scripts like this can be called correctly:

<script>
alert("AHA!");
</script>
<h1>the world is helloed.</h1>

But if I try to push JS into a separate file:

<script type="text/javascript" src="listEntryIndex.js"></script>
<h1>the world is helloed.</h1>

The script will never be called. I really have a lot of googlers and don't get a reason. People ask why their javascripts are not called after loading, but mine, therefore only the tag is not called after loading. Thank!

+3
source share
4 answers

It is not jQuery loadthat the problem basically works: Real-time example This code uses this code:

$("#target").load("http://jsbin.com/oqefe4");

To download this file:

<p>Test</p>
<script src='http://jsbin.com/ewexi4'></script>

... which refers to this:

alert("Hello");

( , , .)

, . , , . , , , .


. . HTML , script ( img ..) HTML current . 404 , , , . by @Darth___ ( , ), ... (): DarthJDG, . , .)

, ,

http://example.com/foo/maindocument.html

load listEntry/listEntryIndex.html openEntry/openEntryIndex.html, :

http://example.com/foo/listEntry/listEntryIndex.html
http://example.com/foo/openEntry/openEntryIndex.html

HTML script, , listEntryIndex.js, maindocument.html, listEntryIndex.html , :

http://example.com/foo/listEntryIndex.js

http://example.com/foo/listEntry/listEntryIndex.js
+3

, script src. :

./currentPage.html
./listEntry/listEntryIndex.html
./listEntry/listEntryIndex.js
./listEntryIndex.js <------------ //This file doesn't exist.

, , , . , , .

+2

:

$.ajax({
  url: "listEntry/listEntryIndex.html",
  dataType: "script",
  success: function(data){
    $("#listEntryDiv").html(data);
  }
});

$.ajax({
  url: "openEntry/openEntryIndex.html",
  dataType: "script",
  success: function(data){
    $("#openEntryDiv").html(data);
  }
});
0

. load() documentation:

jQuery .innerHTML . , , , . , .load(), , .

, <script> <head>, ? , <script>.

0

All Articles