Issues with jQuery, ajax, and jsonp

这一生的挚爱 提交于 2019-12-05 09:14:19

Okay a couple of things jump out at me:

$.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');
  }
});

Also your return does not to appear to be wrapped in a function which is required for jsonp to work.

<auto generated name>({ json object })

The callback function will be named by jquery automatically. So you need a service that will take in a callback parameter and return a json object with padding.

Not sure if this is the problem, but your url is not correct. According to the jQuery docs, it should automatically append the ?callback=? for you:

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

Remove the callback from the URL and try and wrap your json with something like this (php example, $_GET['callback'] is automatically set by 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": ""
})'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!