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 :
$.ajax({
url: 'http://myownajax.projects.it/folder/mypage.aspx ',
success: function(data) {
console.log(data);
}
});
where it easily print "Hello" :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mypage.aspx.cs" Inherits="folder_mypage" %>
Hello
but in fact I get an 200 OK error. Why? How can I fix it?
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);
}
});
You must specify the dataType:"jsonp"
, and cross domain ajax only support type:"GET"
. type:"POST"
is not allowed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.