B-219 Sec-55 Noida, India
+918010221733

How to run ajax in cross domain

Many people face problem when they try to use ajax in cross domain (i.e from any other website).

For example you have ajax script on www.example.com and it want to access test.php file on www.otherexample.com

You should include the below given headers on the top of test.php file

header(‘Access-Control-Allow-Origin: ‘.$_SERVER[‘HTTP_ORIGIN’]);
header(‘Access-Control-Allow-Methods: POST, GET, OPTIONS’);
header(‘Access-Control-Max-Age: 1000’);
header(‘Access-Control-Allow-Headers: Content-Type’);

If it helps you please post thank you in comment 🙂

(Visited 115 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.