我正在 http://www.mywebsite.com 上做跨域Ajax (使用jQuery)调用(http://myownajax.projects.it/folder/mypage.aspx)。
$.ajax({
url: 'http://myownajax.projects.it/folder/mypage.aspx ',
success: function(data) {
console.log(data);
}
});
可以轻松输出“ Hello”:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mypage.aspx.cs" Inherits="folder_mypage" %>
Hello
但老是收到200 OK错误。为什么? 该如何解决?
You must specify the dataType:"jsonp"
, and cross domain ajax only support type:"GET"
. type:"POST"
is not allowed.
Cross site scripting (aka XSS) is blocked by browsers as it is a security risk.
If you must retrieve data from another URL, you must use the JSONP format and GET
requests only.
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);
}
});