这是我第一次使用JSON的经历,所以我可能会做一些非常愚蠢的事。
我构建了一个应用程序来抓取页面并返回一个JSON对象。
我的JSON返回看起来像这样(以Facebook为例):
{"urlTitle":"Welcome to Facebook \u2014 Log in, sign up or learn more","urlDescription":" Facebook is a social utility that connects people with friends and others who work, study and live around them. People use Facebook to keep up with friends, upload an unlimited number of photos, post links and videos, and learn more about the people they meet."}
然而,在FireBug中我得到了上述错误(另见截图)。
我的jQuery代码通过AJAX获取JSON,现在看起来很简单:
$("#submitButton").on("click", function(){
$.ajax({
url: '/miscellaneous/scrape/scrape.cfm',
dataType: 'json',
data: {
strURL: $.param( $("#submitURL").attr("value") )
},
type: 'POST',
success: function(data) {
alert("yes!");
}
});
return false;
});
我从来没有得到我的成功信息:(只是错误!
我在这里做的事情显然是错的吗?
谢谢, 迈克尔。
修改
这是我要求的全部JSON:
{"urlTitle":"Welcome to Facebook \u2014 Log in, sign up or learn more","urlImages":{"image_8":"http:\/\/static.ak.fbcdn.net\/rsrc.php\/v2\/yb\/r\/GsNJNwuI-UM.gif","image_6":"http:\/\/photos-g.ak.fbcdn.net\/photos-ak-snc7\/v85005\/226\/255889644513526\/app_104_255889644513526_1061222291.png","image_7":"http:\/\/secure-us.imrworldwide.com\/cgi-bin\/m?ci=ent156564&am=3&ep=1&at=view&rt=banner&st=image&ca=cmp7747&cr=crv72918&pc=plc220331&r=1346702536","image_4":"http:\/\/photos-a.ak.fbcdn.net\/photos-ak-snc7\/v85006\/156\/156324174503268\/app_104_156324174503268_1504955413.png","image_5":"http:\/\/photos-b.ak.fbcdn.net\/photos-ak-snc7\/v85005\/78\/344521295633922\/app_104_344521295633922_1943760717.png","image_3":"http:\/\/photos-c.ak.fbcdn.net\/photos-ak-snc7\/v85005\/14\/298987460188718\/app_104_298987460188718_170436975.png","image_2":"http:\/\/photos-g.ak.fbcdn.net\/photos-ak-snc7\/v85006\/196\/287530028007964\/app_104_287530028007964_853932327.png","image_1":"http:\/\/static.ak.fbcdn.net\/rsrc.php\/v2\/yY\/r\/2LiCtrj0cdC.png"},"urlDescription":" Facebook is a social utility that connects people with friends and others who work, study and live around them. People use Facebook to keep up with friends, upload an unlimited number of photos, post links and videos, and learn more about the people they meet."}
答案 0 :(得分:0)
您好基于对您的问题的评论..看起来您正在寻找一种方法来避免AJAX请求进行缓存。为此你可以试试这样的东西..
$.ajax({
url: url,
data: inputs + '&ran=' + Math.rand(),
)};
或
$.ajaxSetup ({
// Disable caching of AJAX responses
cache: false
});
我希望这会对你有所帮助。