Home Ajax success function not working with returned json data and status 200/304
Reply: 0

Ajax success function not working with returned json data and status 200/304

user1222
1#
user1222 Published in June 20, 2018, 1:26 am

I'm making an AJAX call that returns a JSON object, and is successfully the JSON in browser. However, the success function isn't fired but rather the error block is hit with the message only saying "error" which isn't much to go on. The status is either 200 or 304 and I can see the object on the network in developer tools so it's there but I can't access that object in the success function.

Here is the ajax call:

$.ajax({
    type: "get",
    dataType: "json",
    jsonp: "false",
    url: "http://my.api.url:8080/quote",                                                                                          
    success: function(r){
        var q = r;
        $("#quote").append(q);
},
    error: function(xhr, status, error) {
        console.log(xhr);
    }
});

The JSON:

{"msg":[{"quote":"quote goes here"}]}

The JSON is generated by an express/node application with response.json() if that effect things, I'm relatively new to those. I have tried setting the jsonp to false, using contentType: 'application/json; charset=utf-8', over datatype json, among other ineffective tries. Any help/critiques are appreciated.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31561 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO