views:

288

answers:

3

Hi,

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.

A: 

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.

Cesar
Well thanks Cesar but, as I said earlier the json formating is correct,I have tried the one you suggest, but It still give a "parsererror".Because I'll use it in an YUI datasource I want to stick to the formating example they give here:var dsLocalJSON = new YAHOO.util.LocalDataSource({ found: 3, total: 20, results: [{name: "apples", type:"fruit", color: "red"}, {name: "broccoli", type:"veg", color: "green"}, {name: "cherries", type:"fruit", color: "red"}]});see:http://developer.yahoo.com/yui/datasource/
Tom
A: 

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

How is that different?
Kinopiko
Thanks Jack,but both ways are correct, I think it has nothing to do with javascript syntax.Somehow the jquery getJSON function doesn't like what it gets from the server side, even though it's valid json.I have googled quite a lot about this "parser Error" but nothing relevant was to be found so far.
Tom
+1  A: 

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

Tom