2

1) I'm trying to use a crossdomain api provided by netrunnerdb.com. The site requires a jsonp request or denies the request.

If you'd like more information on the api visit the website, there's a link for the api at the bottom of the page.

2) It's not my api that I'm calling

-- I have no control over the server, and I think the problem is that the json isn't being returned within the function that jquery sends as the callback.

3) My Ajax request:

var path="http://netrunnerdb.com/api/search/r<t d:c"
$.ajax({
    type:           "GET",
    url:            path,           
    cache:          true,
    dataType:       "jsonp",
    error:          function(xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(ajaxOptions);
        alert(thrownError);
    },
});

Here is the URL sent by the request:

http://netrunnerdb.com/api/search/r%3Ct%20d:c%20?callback=jQuery1110010968961869366467_1390750866847

4) The Response:

I get an error 200 thrown, I receive a parseerror, and then am informed that the json callback wasn't called. Is the response just malformed? Is there a workaround? In chrome if I copy the whole response by browsing directly to the above URL into the console and set a variable equal to it, it parses just fine into an array.

1 Answer 1

2

You are getting the response as JSON instead of JSONP, as the API doesn't recognise the callback from jQuery. The API expects the callback name in the jsonp parameter, not callback.

Add this to the properties in your Ajax call to make jQuery use jsonp instead of callback in the URL:

jsonp: 'jsonp',
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.