Take the 2-minute tour ×

I am doing a simple ajax request to another domain like this:

<script type="text/javascript">
$(function() {
    $('.clik').click(function() {
              type: "POST",
              url: "http://sub.mydomain.com/test.php",
              crossDomain: true,
              success: function(data) {




<p class="clik">Halleluja</p>
<p class="txt"></p>

this is the test.php page on sub.mydomain.com

header('Access-Control-Allow-Origin: http://mydomain.com');
// Begin Session
$session = new Session();
$session->start_session('test', false);

// Access Database
$login_db = new Database('user', 'pass', 'accounts', 'test');
$login_pdo = $login_db->PDO;

include "fn.check_login.php";
if(checkLogin($login_pdo) == true) {

    // We start out by checking if the request has been made using AJAX
    if (is_ajax()) {

        echo "this is working";

    } else {

        echo "this is not working!";


} else {
   echo 'You are not authorized to access this page, please login. <br/>';

// Function to check if the request is an AJAX request
function is_ajax() {

    // BOOLEAN return if AJAX


It returns a semantic issue.

Also if I simply echo some basic text:

echo "Hello World!";

it still returns a semantic issue.

could somebody tell me what went wrong?

share|improve this question
Not an answer but Short tags for php aren't recommended. Always open PHP tags as <?php –  MatthewMcGovern May 1 '13 at 11:00
My Apache server is set to support it, but I'll take your advice. –  Philip Jens Bramsted May 1 '13 at 11:03
Well, for a start, JSONP requests can't be POST (only GET). But I tend to assume jQuery is ignoring the invalid type. –  T.J. Crowder May 1 '13 at 11:03
add comment

2 Answers

up vote 1 down vote accepted

Well, for a start, JSONP requests can't be POST (only GET). But I tend to assume jQuery is ignoring the invalid type. JSONP is intrinsically a GET.

Your response to it is invalid. You've told jQuery you're expecting the server to provide a JSONP response. but your responses aren't JSONP.

A JSONP response would look something like this:

   "property": "value",
   "anotherProperty": 42

...where the name of the callback (callback in the above) is taken from the query string of the request. So for instance, if the request were http://sub.mydomain.com/test.php?callback=foo, the response would use foo for the name of the callback:

   "property": "value",
   "anotherProperty": 42

jQuery will add the callback= query string parameter to the request for you automatically, and generate the corresponding function for you, which in turn calls the ajax success handler with the data passed into it.

share|improve this answer
now it says reference issue. can't find variable: foo –  Philip Jens Bramsted May 1 '13 at 11:10
@PhilipJensBramsted: Read the link about JSONP, and read the $.ajax documentation with regard to how it does JSONP. You don't specify callback in your URL explicitly. As I said above, jQuery will supply that (and the function) for you. Your server-side code just needs to use the callback query string parameter and use that as the name of the function. It'll have some long, weird name (because jQuery auto-generates them and tries to avoid conflicts). –  T.J. Crowder May 1 '13 at 11:24
Sorry sir.. I misunderstood you answer.. Thanks for your time.. Learned a lot from that.. –  Philip Jens Bramsted May 1 '13 at 11:31
@PhilipJensBramsted: Glad that helped! Best, –  T.J. Crowder May 1 '13 at 11:31
add comment

I think you may need to use the jquery postMessage plugin (or similar if there is one). Long time since I tried it but check if you load the script from the server you wish to call (think I tried that and failed in the past but hey - its worth a bash - report back if it does).

share|improve this answer
add comment

Your Answer


