Problems with jQuery, ajax and jsonp

I am using jsonp and ajax to access the web service on another server. Here's jQuery:

$.ajax({
  type: 'GET',
  url: wsurl + 'callback=?',
  dataType: 'jsonp',
  crossDomain: true,
  error: function(data) {
    console.log('error', data);
  },
  success: function(data) {
    console.log('success', data);
  },
  complete: function() {
    console.log('done');
  }
});

The problem is that the error callback is being called. This gives me this useful info:

{
  readyState: 4,
  status: 200,
  statusText: "success"
}

And here is the json file that I am calling:

{
  "id": 0,
  "room_number": "0",
  "first_name": "Admin",
  "last_name": "Istrator",
  "password": "",
  "salutation": "Mr.",
  "telephone": "",
  "email": "",
  "description": "admin",
  "checkin_date": 915797106000,
  "checkout_date": 4071557106000,
  "last_login_date": 947333106000,
  "active_status": true,
  "created_date": 915797106000,
  "created_by": 0,
  "reference_id": ""
}

At first I tried using the getJSON jQuery method with the same result. Thought I'd try to use the basic ajax method as it has a bit more control, but as you can see, no luck. So, pay attention to everything that I do wrong? Think about why it throws an error and gives me a successful value for the statusText property?

EDIT

Ok, I added some options for calling ajax and removed the callback option from the url. Here's the new ajax call:

  $.ajax({
    type: 'GET',
    url: wsurl,
    dataType: 'jsonp',
    crossDomain: true,
    error: function(xhr, textStatus, errorThrown) {
      console.log('textStatus: ' + textStatus);
    },
    success: function(data) {
      console.log('success');
      console.log(data);
    }
  });

, , , , . , textStatus "parsererror". json :

Uncaught SyntaxError: Unexpected token :

?

+5
3

, :

$.ajax({
  type: 'GET',
  #You do not need to append the callback as you have jsonp configured it will  do it    
  #automatically append the callback=<auto generated name>
  url: wsurl, 
  dataType: 'jsonp',
  crossDomain: true,
  error: function(data) {
    console.log('error', data);
  },
  success: function(data) {
    console.log('success', data);
  },
  complete: function() {
    console.log('done');
  }
});

, jsonp.

<auto generated name>({ json object })

jquery. , , json .

+1

, , URL . jQuery, "callback =?". :

http://api.jquery.com/jQuery.ajax/

0

URL- json - ( php, $_GET ['callback'] jQuery):

$_GET['callback'] . '({
  "id": 0,
  "room_number": "0",
  "first_name": "Admin",
  "last_name": "Istrator",
  "password": "",
  "salutation": "Mr.",
  "telephone": "",
  "email": "",
  "description": "admin",
  "checkin_date": 915797106000,
  "checkout_date": 4071557106000,
  "last_login_date": 947333106000,
  "active_status": true,
  "created_date": 915797106000,
  "created_by": 0,
  "reference_id": ""
})'
0

All Articles