2012-09-03 100 views
6

这是我第一次使用JSON的经验,所以我可能在做一些非常愚蠢的事情。jQuery 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; 

}); 

我从来没有让我成功的消息:(刚错误

我做得真的很显然是错误的吗?

感谢, 迈克尔。

enter image description here

编辑

这里是我的整个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

你可以发布json文件的样本吗?好像。我认为它可能是畸形的。 –

+2

这是一个错误Sizzle抛出。你可能以某种方式传递JSON作为像'$(json)'这样的选择器。 – pimvdb

+0

JSON有效:http://jsfiddle.net/esRtf/。正如pimvdb已经说过的那样,它看起来更像是一个Sizzle错误。 *编辑:*它仍然有效:http://jsfiddle.net/esRtf/1/。您必须对您未向我们展示的数据进行处理。 –

回答

0

嗨..看起来像你正在寻找一种方式,以避免AJAX请求做缓存。对于您可以尝试这样的事情..

$.ajax({ 
     url: url, 
     data: inputs + '&ran=' + Math.rand(), 
    )}; 

$.ajaxSetup ({ 
    // Disable caching of AJAX responses 
    cache: false 
}); 

我希望这会帮助你。

相关问题