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:myf开发者_JAVA百科unc
});
$.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.
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
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.
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
精彩评论