将jQuery.Ajax调用的响应(这是一个PHP文件中的字符串)作为javascript函数运行


Running the response of a jQuery .Ajax call (which is a string from a PHP file) as a javascript function

我正在通过.ajax().调用javascript文件中的php函数

我有

$.ajax({
   url: templateDir + 'functions.php',
   async : false,
   data: "function=images",
   success: function (response) {
     alert(response);
   }
});

如果response返回为字符串someObject.someMethod();,我希望解析并运行该字符串。我可以console.log或提醒它,但我无法概念化如何运行返回的字符串。

如果你不知道的话,我是jquery和ajax的新手。

使用eval:

success: function (response) {
    eval(response);
}