2011-08-08 67 views
1

我做跨域調用的代碼:JSONP parseerrror

$.ajax({ 
    type: "GET", 
    url: data.Url, 
    mimeType: "application/javascript", 
    dataType: "jsonp", 
    jsonp: false, 
    cache: true, 
    jsonpCallback: "getData", 
    success: function(data){ 
     callback(data.html); 
    }, 
    error:function (xhr, ajaxOptions, thrownError){ 
     alert('Error during downloading ebook component:'+ componentId + ' thrownError:' + thrownError); 
    } 
}); 

服務器響應與:

HTTP/1.1 200 OK 
x-amz-id-2: YIPtShlPtOmDcIvn3ldRVkONQJTDxFba7OFWnL44A5HVZFXL0+9gGTnO/uZ5muFi 
x-amz-request-id: AF6CF3B66F843250 
Date: Mon, 08 Aug 2011 11:32:52 GMT 
Last-Modified: Mon, 08 Aug 2011 11:24:51 GMT 
ETag: "ee72cfb6fea66192a34b4fa72796b260" 
Accept-Ranges: bytes 
Content-Type: application/octet-stream 
Content-Length: 30 
Server: AmazonS3 

getData({{"html":"example"}}) 

正如你可能已經猜到,錯誤處理程序與執行thrownError:「的getData不叫'和xhr.statusText:'parseerror'。

任何想法?我非常確定,我在週五成功運行了這段代碼(我將代碼與存儲庫進行了比較,但沒有區別),所以我猜測這是服務器響應。

+0

爲什麼'jsonp:'false? – Eric

+0

太棒了,2分鐘後我發佈了這個問題,我找到了answear。 顯然JSON對象不正確,應該有一對括號和分號: getData({「html」:「example」}); – tekado

+0

@Eric jsonp:false,因爲我不想讓jquery add?callback = ...到url,導致這個文件存儲在亞馬遜S3上,然後url不能被改變。 – tekado

回答

3

{{"html":"example"}}不是有效的JSON語法,這就是爲什麼你得到解析錯誤。

試試這個代替{html:"example"}