[英]Why does this ajax call fail?
I'm on http://www.mywebsite.com , and I do a cross-domain ajax call (with jQuery) to http://myownajax.projects.it/folder/mypage.aspx : 我在http://www.mywebsite.com上 ,并且对跨http://myownajax.projects.it/folder/mypage.aspx进行了跨域ajax调用(使用jQuery):
$.ajax({
url: 'http://myownajax.projects.it/folder/mypage.aspx ',
success: function(data) {
console.log(data);
}
});
where it easily print "Hello" : 轻松打印“ Hello”的位置:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mypage.aspx.cs" Inherits="folder_mypage" %>
Hello
but in fact I get an 200 OK error. 但实际上我收到200 OK错误。 Why?
为什么? How can I fix it?
我该如何解决?
Cross site scripting (aka XSS) is blocked by browsers as it is a security risk. 跨站点脚本(aka XSS)被浏览器阻止,因为它存在安全风险。
If you must retrieve data from another URL, you must use the JSONP format and GET
requests only. 如果必须从另一个URL检索数据,则必须仅使用JSONP格式和
GET
请求。
Try this: 尝试这个:
$.ajax({
url: 'http://myownajax.projects.it/folder/mypage.aspx',
type: 'get', // this is optional as 'get' is the default.
datatype: 'jsonp',
success: function(data) {
console.log(data);
}
});
You must specify the dataType:"jsonp"
, and cross domain ajax only support type:"GET"
. 您必须指定
dataType:"jsonp"
,并且跨域ajax仅支持type:"GET"
。 type:"POST"
is not allowed. type:"POST"
不允许使用type:"POST"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.