Tom
Tom

Reputation: 962

Json "Parser Error" from server to client

I use an asp (classic) utility file to create json objects from an SQL database, see: http://code.google.com/p/aspjson/

here is what I get from the server side:

{"results":[{"Opt_Name":"BARR","Opt_FirstName":"TomTest","Comp_Name":"My_Company"}]}

Which is valid json, at least valid for jsonlint.

BUT this never triggers my callback function (Fetch) and I get a ParserError from my error function (myFunc) down here:

$(document).ready(function()
{
    function myfunc(XMLHttpRequest, textStatus, errorThrown)
    {
        alert("call failed " + textStatus + "   error   " + errorThrown + "   Xhr " + XMLHttpRequest);
    }

    $.ajaxSetup({
        error:myfunc
    });

    $.getJSON("jsonGETdataTest.asp", Fetch);

    function Fetch(data)
    {
        alert("blop");
    }
});

I don't know what to do next!

If anyone has a lead on this one I'll be very gratefull. Thanks for stoping by anyway.

Upvotes: 0

Views: 951

Answers (3)

Tom
Tom

Reputation: 962

Ok, Thanks everyone for helping, it looks as I have finally found an answer!

for asp-classic

 response.AddHeader "Content-type", "text/json"

That was the missing part of my response :-s

Upvotes: 1

user105090
user105090

Reputation: 357

Instead of

$.getJSON("jsonGETdataTest.asp", Fetch);

    function Fetch(data)
    {
        alert("blop");
    }

try something like this:

$.getJSON("jsonGETdataTest.asp", function(data){
    ...do something with data object...
    });

see http://docs.jquery.com/GetJSON

Upvotes: 0

Cesar
Cesar

Reputation: 3519

I don't know for asp, but in PHP the correct string will be '[{"Opt_Name":"BARR","Opt_FirstName":"TomTest","Comp_Name":"My_Company"}]'. In PHP I don't have the "results" before.

Upvotes: 0

Related Questions