0

I have this code:

$.ajax({
    type: "POST",
    url: URL,
    data: data,
    dataType: 'jsonp',
    crossDomain: true,
    contentType: "application/json; charset=utf-8",
    jsonpCallback: callback,
    success: function (data,textStatus,jqXHR) {
        alert("success");
    }, 
    error:function(jqXHR, textStatus, errorThrown){
        alert(JSON.stringify(jqXHR));
    },
    complete: function(jqXHR, textStatus){
        alert(JSON.stringify(jqXHR));
    }

});

the the status response is 200 but it's treated as an error. I can see this on chrome response tab:

{
  "error": "cannot create user because user already exists",
  "code": 404
}

<-- this is the data returned by the server

and I can't get that data using jQuery.

1 Answer 1

1

I made it to work with this code:

    $.ajax({
        type: "POST",
        url: URL,
        data: data,
        dataType: 'jsonp',
        crossDomain: true,
        contentType: "text/javascript",
        success: function (data,textStatus,jqXHR) {
             alert(JSON.stringify(data));
        }, 
        error:function(jqXHR, textStatus, errorThrown){
             alert(JSON.stringify(jqXHR));
        },
        complete: function(jqXHR, textStatus){
             alert(JSON.stringify(jqXHR));
        }

    });

hope this help.

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

2 Comments

Thanks for your answer, however I have one question. How does you URL looks like? How do you create your JSONP object?
URL is on a private server and I was "querying" from my local machine. Here are good resources: vaboone.wordpress.com/2011/08/17/jsonp-with-node-js-express and stackoverflow.com/questions/13928391/…

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.