Postman extension get a response, but my jquery request not(邮递员扩展得到响应,但我的 jquery 请求没有)
问题描述
我使用 Postman 扩展发出 GET 请求并获得响应,但是如果我使用 jQuery 发出相同的请求,我会收到一个典型的错误:
I make a GET request using Postman extension and obtain a response, but if I make the same request using jQuery I receive a typical error:
XMLHttpRequest 无法加载http:///www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l=020039535&t=&p=0&e=50L-I.请求中不存在Access-Control-Allow-Origin"标头资源.
XMLHttpRequest cannot load http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l=020039535&t=&p=0&e=50L-I. No 'Access-Control-Allow-Origin' header is present on the requested resource.
为什么会这样?
我的 javascript 代码很简单:
My javascript code is simple:
function getTiempo (dni, piscina, prueba) {
$.ajax({
async: false,
type: "GET",
url: "http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l="+dni+"&t=&p="+piscina+"&e="+prueba
})
.done(function (data) {
console.log(data);
return data;
});
}
Postman 扩展也不在同一个域中,为什么会得到响应?
The Postman extension is not on the same domain either, why does it get a response?
推荐答案
只是为了帮助未来寻求这个特定问题的人:为什么 POSTMAN 有效而我的 jQuery 无效!
Just to help future fellows seeking for this specific question: Why POSTMAN works and my jQuery don't!
实际上,答案很简单:Chrome 扩展程序可以这样做!
The answer is quite simple, actually: Chrome Extensions are allowed to do so!
常规网页可以使用 XMLHttpRequest 对象从远程服务器发送和接收数据,但它们受到同源策略的限制.扩展并没有那么有限.只要首先请求跨域权限,扩展程序就可以与其源之外的远程服务器通信.
Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. Extensions aren't so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions.
https://developer.chrome.com/extensions/xhr
这篇关于邮递员扩展得到响应,但我的 jquery 请求没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:邮递员扩展得到响应,但我的 jquery 请求没有
基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
