与AJAX实例上W3Schools的问题实例、问题、AJAX、W3Schools

2023-09-10 14:28:03 作者:孟婆丶来杯香飘飘

链接的例子。

我通过一个网站的网址替换URLajax_info.txt。由此产生的code工作在IE 8。

I replaced the URL 'ajax_info.txt' by a website URL (http://...) which responds with some text. The resulting code works in IE 8.

为什么code不工作的Chrome浏览器(不responseText的)?

Why is the code not working for Chrome (no responseText)?

如何解决(不使用任何库)?

What is the solution (without using any library)?

感谢您的时间。

PS:的我是很新的Web开发。

P.S: I am very new to web development.

推荐答案

浏览器有安全限制,所谓的同根同源的政策。它prevents使用通过cookie或localStorage的存储在浏览器您的身份信息,以您的名义发出请求随机网站。例如,如果w3schools.com可以让一个Ajax请求facebook.com它可以找出你住,或谁是你的朋友,如果你在Facebook的信息。浏览器prevent这样的请求,只允许AJAX请求发出请求到域,端口和协议(HTTP或HTTPS为例),该文件来源于

Browsers have a security limitation called 'same origin policy.' It prevents random websites from making requests on your behalf using your identity information stored in the browser via cookies or localStorage. For example if w3schools.com could make an AJAX request to facebook.com it could find out where you lived or who your friends are if you have that information on Facebook. Browsers prevent this kind of a request by only allowing AJAX requests to make requests to the domain, port and protocol (http or https for example) that the document originated from.

详细信息:

http://en.wikipedia.org/wiki/Same_origin_policy

这就是为什么你的要求在Chrome没有工作,假定你把一些随机的网站的URL中的文本文件。我不知道为什么它会工作了IE 8,我怀疑它会。

This is why your request did not work in Chrome, assuming you put some random site's URL in place of the text file. I am not sure why it would have worked for IE 8. I doubt it would.

 
精彩推荐
图片推荐