2012-04-29 48 views
0

http://www.thaicreate.com/jquery/jquery-ajax-jquery-getjson.html

http://www.thaicreate.com/jQuery-Demo/jQuerygetJSON.html

此代碼不能正常工作?爲什麼?

<html> 
    <head> 
     <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> 
     <title>ThaiCreate.Com jQuery Tutorials</title> 
     <script type="text/javascript" 
     src="http://www.thaicreate.com/jQuery-Demo/jquery-1.6.4.js"></script> 
     <script type="text/javascript"> 
     $(document).ready(function() { 

      $("#btn1").click(function() { 

       $.getJSON("http://www.thaicreate.com/jQuery-Demo/json.js", function (result) { 
        $.each(result, function (i, field) { 
        $("#div1").append(field + "<br/>"); 
        }); 
       }); 

      }); 

     }); 
     </script> 
    </head> 
    <body> 
     <div id="div1"></div> 
     <input id="btn1" value="Load" type="button"> 
    </body> 
</html> 
+0

它在Chrome 18中適用於我。編輯:現在,我看到你更改了代碼中的URL。 – miguelr 2012-04-29 09:41:01

回答

0

,因爲這要求是cross-domain你不能在URL字段中使用的absolute path。爲此需要包括dataTypeJSONP。將json.js文件複製到本地磁盤會更容易。