全栈工程师开发手册 (作者:栾鹏)
jquery系列教程6-AJAX全解
jquery中ajax加载js文件
jquery中ajax加载js文件的函数为getScript()
代码如下:
$.getScript("index5.js",function(){
alert("载入完成");
});
jquery中ajax加载json文件
jquery中ajax加载json文件的函数为getJSON()
代码如下:
$.getJSON("test.JSON",function(data){ //data为返回的数据
$.each(data.myback,function(commentindex,comment){ //$.each遍历数组和对象,commentindex对象成员或数组索引,comment对应变量或内容
return false; //返回false即可退出each函数
});
});