Reputation: 47947
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?
Upvotes: 1
Views: 198
Reputation: 337560
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);
}
});
Upvotes: 5
Reputation: 121
You must specify the dataType:"jsonp"
, and cross domain ajax only support type:"GET"
. type:"POST"
is not allowed.
Upvotes: 2