Quantcast
Viewing all articles
Browse latest Browse all 16

Jquery Ajax Cross-site error

This article is all about how to get jQuery AJAX cross-site calls working correctly. It assumes that you operate the server that the cross-site AJAX code is communicating to.

When configuring jQuert AJAX calls to work across different servers we kept getting the error “a is null” in the jQuery AJAX response. In particluar I was trying to get the AJAX call to work using XML as the communication method. After looking around online for a bit we found lots of cross site solutions ranging from using jquery json variations instead through to setting up some proxy code in PHP to grab the response for you.

These are overkill and there is a really simple solution. Just add this following line of code to the PHP file that the jQuery AJAX is trying to communicate to:
header(‘Access-Control-Allow-Origin: *’);

This simple line of code tells the server that it will allow cross-site communications to it… Which is what the AJAX will be trying to do. I’m not sure about the answer for ASP.NET servers but there is bound to be a similar solution.


Filed under: Ajax, PHP Tagged: Ajax, Cross-site scripting, php Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 16

Trending Articles