简体   繁体   中英

JQuery ajax get error :unexpected token :

I have to do an ajax get to retrieve data from OData service, this is my code :

$.ajax({
  url : "https://systempath/servicename",
  type: "GET", //or POST?
  dataType: "jsonp",

  xhrFields: 
   {
  withCredentials: true
   },
  beforeSend: function (request)
   {
  request.setRequestHeader("Authorization", "Basic");
   },

  success: function(){alert("ok")},
  error: function(){alert("error")}
})

But i get this error :

Uncaught SyntaxError: Unexpected token :

If i consult the network, i find my response in JSON format, but the error function is executed not the success function.

This is my response: responseOdata

The issue with your code is the dataType that you defined, make sure that the responses headers are corrects with your req. Test with the dataType:'text', this might works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM