2016-09-14 26 views
0

我的繼承人Ajax請求語法錯誤在jquery.ajax GET請求:1追加到URL

$.ajax({ 
    url: req_url, 
    contentType: 'application/json', 
    type: 'GET', 
    dataType:'jsonp', 
    success: function(data){ 
     console.log(data); 
    }, 
}) 

和錯誤

?id=BLC&format=json&starttime=2016-09-13&callback=jQuery3100840…
1473881883047&=147388…:1 Uncaught SyntaxError: Unexpected token :

刪除所有緩存的jQuery附加在我使用的結束這個代碼

$.ajax({ 
    url: req_url, 
    contentType: 'application/json', 
    type: 'GET', 
    dataType:'jsonp', 
    jsonp: false, 
    jsonpCallback: 'callback', 
    cache: true, 
    success: function(data){ 
     console.log(data); 
    }, 
}) 

和這裏的錯誤是一樣的

?id=BRD&format=json&starttime=2016-09-13:1 Uncaught SyntaxError: Unexpected token :

+0

這應該被忽略。它被稱爲「緩存破壞者」並且是無害的。它只是改變URL,就足以繞過緩存。 –

+0

[爲什麼jQuery.ajax()將參數添加到url?](http://stackoverflow.com/questions/2749560/why-does-jquery-ajax-add-a-parameter-to-the -url) –

+0

@NativeCoder看起來不像緩存中斷器。它作爲附加參數被添加,它不會修改現有的參數。 – Barmar

回答

0

@Bamar對於cache-buster是正確的。我相信這是因爲你正在使用jsonp。嘗試只用

datatype: json 

除非,你需要一個跨域請求......

編輯:

而是編碼參數自己,讓jQuery的爲你做它的URL。嘗試像

$.ajax({ 
url: 'http://www.foo.com/', 
data: YourData.serilize(), 
contentType: 'application/json', 
type: 'GET', 
dataType:'jsonp', 
success: function(data){ 
    console.log(data); 
}, 
}) 
+0

由於同源策略,這可能會失敗。 – Barmar

+0

是的,我得到了同樣的政策 – jasminder88

+0

您是否嘗試過使用數據參數? –