Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross-domain AJAX post call

I've to make a POST call(with parameter) to an asp form which is located on another server.

For development, I did this on the same server, and it works perfectly, but now I'm testing it on another server, and instead of receiving a 200 status, I receive a 0 status.

I think it's because it's a cross-domain AJAX call, it's the only thing which changed. So how can I make this call? Is there any file I can put on the server/client to allow this call(like flash, ...)?

Thank you!

like image 603
J4N Avatar asked Jul 25 '11 06:07

J4N


People also ask

Can you do cross domain Ajax?

For a successful cross-domain communication, we need to use dataType “jsonp” in jquery ajax call. JSONP or “JSON with padding” is a complement to the base JSON data format which provides a method to request data from a server in a different domain, something prohibited by typical web browsers.

What is Ajax post call?

Sends an asynchronous http POST request to load data from the server. Its general form is: jQuery. post( url [, data ] [, success ] [, dataType ] ) url : is the only mandatory parameter.

How do I create a cross origin Ajax request?

For instance, if sending a request from http://www.example.com, any of the following would be "cross origin": http://mail.example.com (domain differs) https://www.example.com (protocol differs) http://www.example.com:8080 (port differs)


1 Answers

Yes, assuming you can change the server you connect to

You can implement Cross Origin Resource Sharing (CORS)

You need the server to return Access-Control-Allow-Origin: * if you want to allow all domains to access, otherwise return Access-Control-Allow-Origin: http://yourdomain.com

If you cannot change the server you are accessing, you need to use a proxy on the server your script comes from - alternatively investigate if they have published an API to return for example JSONP

More details here

  • MDN HTTP access control (how)
  • W3Org (Implemation details)
  • MSDN XDR

and several links to the right of this questions

like image 62
mplungjan Avatar answered Sep 27 '22 22:09

mplungjan