2012-09-03 96 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 
}); 

我希望這會幫助你。

相關問題