猿问

Ajax----getJSON(url,args,function(data){});

/*

*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处出错

菜的
浏览 2055回答 1
1回答

qq_infinite

你的目标url是helloAjax.js,getJSON的目标应该是json,比如$.getJSON('test.json', function(data){}),你把文件的后缀名改为json应该可以了
随时随地看视频慕课网APP

相关分类

Java
JavaScript
我要回答