[英]is there a straightforward way to retrieve text that is rendered by the browser but is not hard-coded in the actual html file?
[英]Crossdomain JSONP with text file and hard-coded callback
我知道這是一個很普遍的問題,人們可以通過在服務器端編寫代理來解決。 但我想避免這種情況,我有一個帶有硬編碼回調jsonResponse()
:
jsonpResponse({"keys": ["0", "2", "3", "4", "5", "6"], "promoted": [3, 10, 44, 47, 47, 31], "upcoming": [187, 14, 285, 366, 322, 225]});
我想用JQuery.ajax()
從另一個域獲取它:
$.ajax({
type: "GET",
url: URL + filename,
dataType: "text jsonp",
jsonpCallback: "jsonpResponse",
success: function(data) {
// wrapping data
}
});
我得到一個錯誤:
XMLHttpRequest cannot load http://first.domain/filename.jsonp.
Origin http://second.domain is not allowed by Access-Control-Allow-Origin.
有什么辦法可以做我想要的嗎? 我真的必須使用代理嗎? 如果是真的,那為什么呢?
您在錯誤地調用$.ajax
。
您需要傳遞dataType: "jsonp"
; 它不支持多個值。
請注意,由於您使用的是固定的回調,因此您將無法發出多個並發請求,否則它們將竊取彼此的回調。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.