Olga Real Olga Real - 1 month ago 9
Ajax Question

JSON that contains functions

I have a website that returns a JSON-like data structure like this:

{
"name":"tom jones",
"no": 123,
"storedproc": function(){
callbuyer(0123);
}
}


I'm getting this data using
$.ajax()
with dataType "JSON". Unfortunately, my
$.ajax()
calls the error callback because my data contains a function().
How can I parse this correctly? I really need to store the function in a variable and call it later.

Answer

Could you arrange to have the server return JSON like this:

{"name":"tom jones",
  "no": 123,
 "storeprocFn": callbuyer,
 "arg": "0123"};

Then your callback function can call the callbuyer function and pass arg