想做个测试,但发现此回调函数并没有被调用,为什么?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/ TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
* {
margin: 0;
padding: 0;
} body {
font-size: 12px;
} #loading {
width: 80px;
height: 20px;
background: #bbb;
color: #000;
display: none;
} img {
border: 0;
height: 100px;
width: 100px;
} .comment {
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
background: #DDD;
} .comment h6 {
font-weight: 700;
font-size: 14px;
} .para {
margin-top: 5px;
text-indent: 2em;
background: #DDD;
}
</style>
<!-- 引入jQuery -->
<script src="../../js/jquery-1.4.3.js" type="text/javascript"></script>
<script>
$(function() {
//demo1:
$('#send1').click(function() {
$("#resText1").empty();
$.ajax({
url:"http://api.flickr.com/services/feeds/photos_public.gne?tags=car&tagmode=any&format=json&jsoncallback=?",
beforeSend:function(xhr) {
alert('send') ;
},
success: function(data) {
alert('suc');
$.each(data.items, function(i, item) {
$("<img/> ").attr("src", item.media.m).appendTo("#resText1");
if (i == 3) {
return false;
}
});
},
complete:function() {
alert('complete')
},
dataType:"json"
})
});
//demo2:
$("#send2").click(function() {
$.post("get1.jsp", {
username : $("#username").val() ,
content : $("#content").val()
}, function (data, textStatus) {
$("#resText2").html(data); // 把返回的数据添加到页面上
}
);
})
})
</script>
</head>
<body>
<br/><div id="loading">加载中...</div><br/>
Demo1:
<br/>
<input type="button" id="send1" value="加载"/><div id="resText1"></div>
<br/>
Demo2:
<br/><form id="form1">
<p>评论:</p> <p>姓名: <input type="text" name="username" id="username"/></p> <p>内容: <textarea name="content" id="content"></textarea></p> <p><input type="button" id="send2" value="提交"/></p>
</form>
<div class='comment'>已有评论:</div>
<div id="resText2">
</div>
</body>
</html>
"http://www.w3.org/ TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
* {
margin: 0;
padding: 0;
} body {
font-size: 12px;
} #loading {
width: 80px;
height: 20px;
background: #bbb;
color: #000;
display: none;
} img {
border: 0;
height: 100px;
width: 100px;
} .comment {
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
background: #DDD;
} .comment h6 {
font-weight: 700;
font-size: 14px;
} .para {
margin-top: 5px;
text-indent: 2em;
background: #DDD;
}
</style>
<!-- 引入jQuery -->
<script src="../../js/jquery-1.4.3.js" type="text/javascript"></script>
<script>
$(function() {
//demo1:
$('#send1').click(function() {
$("#resText1").empty();
$.ajax({
url:"http://api.flickr.com/services/feeds/photos_public.gne?tags=car&tagmode=any&format=json&jsoncallback=?",
beforeSend:function(xhr) {
alert('send') ;
},
success: function(data) {
alert('suc');
$.each(data.items, function(i, item) {
$("<img/> ").attr("src", item.media.m).appendTo("#resText1");
if (i == 3) {
return false;
}
});
},
complete:function() {
alert('complete')
},
dataType:"json"
})
});
//demo2:
$("#send2").click(function() {
$.post("get1.jsp", {
username : $("#username").val() ,
content : $("#content").val()
}, function (data, textStatus) {
$("#resText2").html(data); // 把返回的数据添加到页面上
}
);
})
})
</script>
</head>
<body>
<br/><div id="loading">加载中...</div><br/>
Demo1:
<br/>
<input type="button" id="send1" value="加载"/><div id="resText1"></div>
<br/>
Demo2:
<br/><form id="form1">
<p>评论:</p> <p>姓名: <input type="text" name="username" id="username"/></p> <p>内容: <textarea name="content" id="content"></textarea></p> <p><input type="button" id="send2" value="提交"/></p>
</form>
<div class='comment'>已有评论:</div>
<div id="resText2">
</div>
</body>
</html>
就把dataType这个参数略去
({
"title": "Recent Uploads tagged car",
"link": "http://www.flickr.com/photos/tags/car/",
"description": "",
"modified": "2010-10-19T02:30:11Z",
"generator": "http://www.flickr.com/",
"items": [
{
"title": "20970 2010 Fall Classic Car Show Jim Price Chevrolet",
"link": "http://www.flickr.com/photos/bsabarnowl/5095660330/",
"media": {"m":"http://farm5.static.flickr.com/4147/5095660330_f28875f8b8_m.jpg"},
"date_taken": "2010-10-16T14:45:03-08:00",
"description": " <p><a href=\"http://www.flickr.com/people/bsabarnowl/\">bsabarnowl<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/bsabarnowl/5095660330/\" title=\"20970 2010 Fall Classic Car Show Jim Price Chevrolet\"><img src=\"http://farm5.static.flickr.com/4147/5095660330_f28875f8b8_m.jpg\" width=\"240\" height=\"180\" alt=\"20970 2010 Fall Classic Car Show Jim Price Chevrolet\" /><\/a><\/p> <p>Classic Car Show<br /> Jim Price Chevrolet<br /> Charlottesville, Virginia<br /> October 16, 2010<\/p>",
"published": "2010-10-19T02:30:11Z",
"author": "[email protected] (bsabarnowl)",
"author_id": "10966541@N02",
"tags": "show classic chevrolet car virginia charlottesville jimprice 20101016"
}
})