問(wèn)題描述
我正在嘗試通過(guò) HTTP 從 JavaScript 獲取一些簡(jiǎn)單的文本:
I'm trying to fetch some simple text over HTTP from JavaScript:
$(function() {
$.get("http://mydomain.com/path", function(result) {
console.log(result);
});
});
結(jié)果應(yīng)該是text/html
,但基本上只是一個(gè)簡(jiǎn)單的鍵值字符串,沒(méi)有任何HTML標(biāo)簽.該頁(yè)面由我控制,但由第三方(閉源)提供,因此我無(wú)法修改提供此頁(yè)面的 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 獲取此頁(yè)面的內(nèi)容?
How can I get the contents of this page from JavaScript?
推薦答案
你只需要使用 PHP/ASP 你的服務(wù)器端語(yǔ)言來(lái)檢索跨域請(qǐng)求或使用由 Yahoo! 創(chuàng)建的跨域 ajax 服務(wù)等服務(wù).
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,它允許執(zhí)行非常嚴(yán)格的跨域請(qǐng)求,但來(lái)自 Yahoo!他們將檢索互聯(lián)網(wǎng)上的任何頁(yè)面.
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/
這篇關(guān)于Access-Control-Allow-Origin 不允許 XMLHttpRequest Origin的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!