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.
Jquery Ajax Cross-site error
Need help building your tech ideas?
Scorchsoft are expert app and portal developers in the UK. 14 years experience.
Need help building your tech ideas?
Scorchsoft are expert app and portal developers in the UK. 14 years experience.
Need Help? Learn more Contact UsWe Make
Mobile Apps, Portals, SaaS, & Progressive Web Apps
All Case Studies
Discover How Scorchsoft Can Help
We would love to hear about your project. Please contact us, and share your goals; we'll respond with our thoughts and a rough cost estimate.
Scorchsoft is a UK-based team of web and mobile app developers and designers. We operate in-house from Birmingham, and our offices are located in the heart of the Jewellery Quarter.
Scorchsoft develops online portals, applications, web apps, and mobile app projects. With over fourteen years experience working with hundreds of small, medium, and large enterprises, in a diverse range of sectors, we'd love to discover how we can apply our expertise to your project.