I have a JSON object with a key element called callback.
{
"id":34,
"description":"",
"item_id":4,
"callback":"addNew",
"filename":"0000072.doc",
"type":"News",
"ext":"doc",
"size":46592
}
I would like to call the javascript "addNew" function. I tried.
json.callback(json);
But does not work. Any idea?
Assuming it is a global function (it shouldn't be):
window[json.callback](json);
If your code is well structured you will probably have an object containing all the functions the JSON could call.
var myObject = {
func1: function myObject_func1_method(foo) {
return 1;
},
func2: function myObject_func2_method(foo) {
return 2;
}
}
Then you can:
myObject[json.callback](json);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With