Is it possible to add a callback to eval(data);?
So when eval(data) is complete, how would 开发者_开发百科you set a callback?
Eval is not asynchronous, so you don't need a callback. Just put your function call on the next line.
The script you are evalling might do something asynchronous, in which case you would need to parse the JS, find the asynchronous code, and add a callback to that (in string form).
Best to avoid eval in the first place though. It is almost never the right solution to a problem.
Just put the code you want to execute on callback in the data that is going to be evaluated. Of course you will have problem if in the evaluated data you have some dynamic generated function that runs asynchronously.
eval(data)
is a blocking call. All you have to do is put your "callback" code after your eval()
call, and it will be executed once the eval()
is finished.
精彩评论