2014-06-05 42 views
1

你好,我正在創建一個jsonp API,我在我的$.ajax()設置中使用cache = false。但是,我的服務器在每個url GET參數前面都需要一個特定的前綴。jQuery jsonp緩存,有沒有辦法改變時間戳url key?

ex。 http://www.domain.com/test?_prefix_age=29

我已經完成了這樣的事情,但我不能找到一種方法來增加我的前綴緩存時間戳參數_:{TIMESTAMP}

從jQuery的$.ajax()文檔:

緩存(默認:真,假的dataType'script'和'jsonp')類型: 布爾如果設置爲false,它將強制請求的頁面不被瀏覽器緩存爲 。注意:將緩存設置爲false只能正確使用HEAD和GET請求 。它通過在GET參數中追加 「_ = {timestamp}」來工作。 其他類型的請求不需要此參數,IE8中除POST已發送到已由GET請求的URL 外。

是否有任何方法可以添加timestamp參數的前綴infront,而不會在內部搞亂jQuery?

回答

0

你可以不使用jQuery。例如:

<script> 
function processJSON (json) { 
    // Do something with the JSON response 
}; 

// Create a new script element 
var script_element = document.createElement('script'); 

// Set its source to the JSONP API 
script_element.src = 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=processJSON&tags=monkey&tagmode=any&format=json'; 

// Stick the script element in the page <head> 
document.getElementsByTagName('head')[0].appendChild(script_element); 
</script> 

創建自己的JSONP函數的障礙可能足夠低,以至於跳過試圖讓jquery工作?

取自http://schock.net/articles/2013/02/05/how-jsonp-really-works-examples/

相關問題