How do I handle a JSON request returning a String in JQuery?

Posted by knt on Stack Overflow See other posts from Stack Overflow or by knt
Published on 2010-05-03T05:56:35Z Indexed on 2010/05/03 6:08 UTC
Read the original article Hit count: 327

Filed under:
|
|

Hi all,

New to json/jQuery so sorry if this has an obvious answer.

I'm doing an ajax request in jQuery that's something like:

$.ajax({
        url: theURL,
        dataType: 'jsonp',
        type: 'get',
        success: function(data) {
            alert("it's there");
        }
    });

The request asks whether a given object is in a database. If it is, it returns something of the format:

    {
    "text": "duck", 
    "canonical_name": "duck", 
    "language": {
        "id": "en"
    }}

However, if the object isn't there, it returns:

Not Found

As in...literally that exact string, not in any kind of json format as far as I know. Is there any way I can get my ajax to detect this? Right now it doesn't even seem to be acknowledging that it got anything back in the latter case.

The json code wasn't written by me. It can possibly be fixed if this is not the correct format and there's absolutely nothing I can do from my end to work with this, but I'd really like to try to find some kind of workaround if possible.

Thanks very much!

© Stack Overflow or respective owner

Related posts about JSON

Related posts about jQuery