1

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?

2 Answers 2

5

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); } }); 
Sign up to request clarification or add additional context in comments.

9 Comments

It said "Hello is not defined" : I need a conversion to JSON? Or what?
How are you accessing the variable? I assume the code you are using is not the same as you have posted as you would get a different error.
Change your .aspx page to return a string which can be parsed into JSON format, in your example this would be ["Hello"]
Uhm, in fact I need to send a whole page to the client! How can I do?
It's best to open another question for that - don't forget to mark this one as accepted though ;)
|
2

You must specify the dataType:"jsonp", and cross domain ajax only support type:"GET". type:"POST" is not allowed.

2 Comments

It works! Now I get "Hello is not defined". I think I need a conversion?
It is not possible to fetch HTML from other domain. FYR

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.