我想写一个javascript函数,它将向PHP脚本发出ajax请求并返回它的结果.这就是它的样子:
function myjsfunc(some_data)
{
$.post(
"/myscript.php",
{ some_data: some_data },
function(response)
{
result = response;
}
);
return result;
}
Run Code Online (Sandbox Code Playgroud)
问题是,这result总是未定义的.这可能是因为变量result不在myjsfunc命名空间中?或者是因为在处理主函数后接收到成功函数结果?
无论如何,我怎样才能获得理想的结果?有办法吗?