Call Jquery and ajax between two different domain (cross-domain)


Hi

If You have to call one page index.htmlfrom http://domain1.com to http://domain2.com
then You have to add code given below in top of index.html file of http://domain1.com in the top

switch ($_SERVER['HTTP_ORIGIN']) {
case 'http://domain1.com': case 'https://domain1.com':
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');
break;
}

and call jquery or ajax in page of http://domain2.com.

It will be allow to access to access via ajax/jquery cross domain.

thanks.

Advertisements

5 responses to “Call Jquery and ajax between two different domain (cross-domain)

  1. Generally I do not learn article on blogs, however I wish
    to say that this write-up very pressured me to try and do it!
    Your writing style has been amazed me. Thank you, very great post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s