問題描述
我正在嘗試通過 HTTP 從 JavaScript 獲取一些簡單的文本:
I'm trying to fetch some simple text over HTTP from JavaScript:
$(function() {
$.get("http://mydomain.com/path", function(result) {
console.log(result);
});
});
結果應該是text/html
,但基本上只是一個簡單的鍵值字符串,沒有任何HTML標簽.該頁面由我控制,但由第三方(閉源)提供,因此我無法修改提供此頁面的 Java.
The result should be text/html
, but is basically only a simple key-value string, no HTML tags whatsoever. The page is in my control, but is supplied by a third-party (closed-source) so I can't modify the Java that serves out this page.
如何從 JavaScript 獲取此頁面的內容?
How can I get the contents of this page from JavaScript?
推薦答案
你只需要使用 PHP/ASP 你的服務器端語言來檢索跨域請求或使用由 Yahoo! 創建的跨域 ajax 服務等服務.
You've simply gotta use either PHP/ASP your serverside language to retrieve the cross-domain request or use a service such as a cross domain ajax service created by Yahoo!.
它使用 JSONP,它允許執行非常嚴格的跨域請求,但來自 Yahoo!他們將檢索互聯網上的任何頁面.
It uses JSONP which is allowed to do very strict cross-domain requests, but asking from Yahoo! they will retrieve any page on the internet.
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
這篇關于Access-Control-Allow-Origin 不允許 XMLHttpRequest Origin的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!