weixin_33674976 2015-09-03 08:58 采纳率: 0%
浏览 29

OData Ajax调用错误

I have an $.ajax call in one of my html page:

var query = ODATA QUERY

jQuery.ajax({
     dataType: 'jsonp',
     url: query,
     jsonpCallback: 'callback',
     success: callback,
     ajaxError: alert("test"),
     timeout: 100
    });


  function callback(result) { }

but I have a problem, message alert appears if the query succeed but even if the query produces error. Why?

Thanks

EDIT: I try to update code with:

jQuery.ajax({
      dataType: 'jsonp',
      url: query,
      jsonpCallback: 'callback',
      success: callback,
      ajaxError : errore
 });

 function callback(result) { }
 function errore() {console.log("errore"); }

but if the query fails i get an errore in console (NetworkError: 400 Bad Request) but does not enter in the error function

  • 写回答

1条回答 默认 最新

  • weixin_33735676 2015-09-03 09:01
    关注

    You are calling alert immediately and assigning its return value to ajaxError.

    You need to assign a function there instead.


    You then have two additional problems.

    1. ajaxError appears to be a global event handler and not an option you can pass in the options object to ajax. You probably want error instead.
    2. Both error and ajaxError say:

    This handler is not called for cross-domain script and cross-domain JSONP requests.

    评论

报告相同问题?