【发布时间】:2012-08-28 12:18:29
【问题描述】:
这是我第一次使用 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."}
【问题讨论】:
-
你能发布一个json文件的样本吗?好像。我说它可能是畸形的。
-
这是 Sizzle 抛出的错误。您可能以某种方式将 JSON 作为选择器传递,例如
$(json)。 -
JSON 有效:jsfiddle.net/esRtf。正如 pimvdb 已经说过的,它看起来更像是一个 Sizzle 错误。 edit: 仍然有效:jsfiddle.net/esRtf/1。您必须对未向我们显示的数据执行某些操作。
-
总是在 jquery ajax 请求中引用你的数据
-
你不需要 $.param
标签: javascript jquery json