How to define ajax cross domain request in php
Edit2: If you use jQuery.ajax function like this:
var request = $.ajax({
url: "http://somesite.com/somescript.php?somevar=somevalue",
dataType: "jsonp",
jsonp: 'callback',
success: function(data) {
alert('Done!');
}
});
Then you can check the variable $_SERVER['REQUEST_URI']
or just $_GET['callback']
and $_GET['_']
. REQUEST_URI will look like this:
/somescript.php?somevar=somevalue&callback=jQuery172028849187534502896_1333494007273& _ = 1333494443880
Edit: The answer below is to see if it's cross-domain or not, rather than checking if it's AJAX
Answer to the question "How to determine if an ajax call is from another domain":
I am using jQuery.ajax call and for me using variable $_SERVER['HTTP_REFERER']
works fine.
If I use the page on my local machine, this superglobal returns an empty string.
If I am using a page on the web, the value $_SERVER['HTTP_REFERER']
returns the url of the page that made the ajax call. So checking the meaning of this can tell you what you need to know.
source to share