从该函数返回数据的唯一方法是进行同步调用而不是异步调用,但这将使浏览器在等待响应时冻结。
您可以传入一个处理结果的回调函数:
function testAjax(handleData) { $.ajax({ url:"getvalue.php", success:function(data) { handleData(data); } });}这样称呼它:
testAjax(function(output){ // here you use the output});// Note: the call won't wait for the result,// so it will continue with the pre here while waiting.


