/**getJSON函数*/<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body><h1>People</h1> <a href="file/helloAjax.js">hello</a> <div id="text">xixi</div></body><script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script><script type="text/javascript"> $(function(){ $("a").click(function() { //使用getJSON方法 处理Ajax var url = this.href; var args={"date":new Date()}; $.getJSON(url,args,function(data){ var name = data.people.name; var age = data.people.age; var favorite = data.people.favorite; $("#text").empty().append("<h2>name:"+name+" age:"+age+" favorite:"+favorite+"</h2>"); }); return false; }</script></html>/** * helloAjax.js */{ "people":[{ "name":"li", "age":11, "favorite":"apple" }]}问题描述:代码执行到getJSON处出错
1 回答
qq_infinite
TA贡献14条经验 获得超10个赞
你的目标url是helloAjax.js,getJSON的目标应该是json,比如$.getJSON('test.json', function(data){}),你把文件的后缀名改为json应该可以了
添加回答
举报
0/150
提交
取消