2011-07-02 40 views
0

這裏的test.html:無法獲取jQuery的阿賈克斯或.load執行腳本

<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script> 
</head> 
<body> 
<script language=javascript> 

$(document).ready(function() { 
      $("button").click(function() { 
      $.ajax({ 
      url : "http://localhost:101/test2.html", 
      dataType : "html", 
      success: function(data){ alert(data); $("div").html(data); } 
      }); 
      }); 
}); 
/* 
$(document).ready(function() { 
      $.ajax({ 
      url : "http://localhost:101/Scripts/testscript.js", 
      dataType : "script" 
      //success: function(data){ $("#inner-main").html(data); } 
      }); 
}); 
*/ 
</script> 
<button> bleh </button> 
<div> </div> 
</body> 
</html> 

這裏的test2.html:

<script type=javascript> 
alert("lock and load, outside!"); 
            $(document).ready(function() { 
             alert("lock and load!"); 
            });  

</script> 
<p>Hello, world </p> 

我不能讓test1的加載TEST2,並在其中執行腳本。 我確實得到< p>(Hello World)在div中顯示。儘管如此,腳本不會執行。 我看到的唯一警報來自成功調用的函數。

我在做什麼錯?

的URL test1.html是http://localhost:101/test1.html

+0

Javascript控制檯中的任何錯誤? –

+0

不,不是在IE9(F12開發人員工具,腳本選項卡) – Anon

+0

我試着運行這是IE9,歌劇11,Chrome瀏覽器。在其中任何一個都不起作用。 – Anon

回答

1

在這兩個腳本,改變

<script language=javascript><script type=javascript>

<script type="text/javascript"> 

它將工作。

學習和使用AJAX之前,我建議你先學會有效的HTML。這不是有效的HTML,爲什麼jQuery甚至瀏覽器會正確編譯它?

+2

這是正確的信息,但它應該工作,即使這個破損 –

+0

不,它_should_不。當然,也可能但如果是那麼它只是一個偶然的事情。 –

0

編輯: 試試這個網址在您的Ajax調用:

url : "test2.html", 

希望這有助於。乾杯

+0

Trie。沒有幫助 – Anon