1

I'm using jaubourg's jquery-jsonp module to fetch data from a different domain than my site is on. I'm using this module since jQuery's ajax function doesn't support error handling for JSONP requests.

When I make a request using the jsonp function of this library to a non-existing URL, the error callback function is called, but I can't see how I can retrieve the HTTP error code, to see what went wrong.

According to the documentation, the only data available in the error callback function is the xOptions object that defines the request, and a textStatus string which is either "error" or "timeout". In my case it's "error", but I can't see how I can see which error has happened.

1
  • Are you sure jQuery ajax does not support that? >> "complete callback option fires, when the request finishes, whether in failure or success. It receives the jqXHR object, as well as a string containing the success or error code." Commented Feb 19, 2014 at 15:30

1 Answer 1

1

You can't

Let's recall what JSONP does. Consider this:

$.jsonp({
  url: "http://service.org/path?param1=xx&param2=xx",
  callback: "myCbFn",
  error: myErFn
});

What this will do is add something like this to the DOM:

<script type="application/javascript"
        src="http://service.org/path?param1=xx&param2=xx&jsonp=myCbFn"
        onerror="myErFn">
</script>

Your error handling function will be called by the DOM event on the script tag.

It's very important to distinguish JSONP from AJAX (XML HTTP Request).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.