How to detect ajax cross domain request in php
问题 For the normal ajax request I use: strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' But this don't work with cross domain request. How can I do? 回答1: Edit2: If you're using jQuery.ajax function in this way: 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 $_SERVER['REQUEST_URI'] variable, or simply $_GET['callback'] and $_GET['_'] .