我希望使用jQuery.post类来返回(不警告)函数内的响应。返回jQuery Ajax Post
下面给出具有适当值的警报:
function test_func() {
$.post("test.php", { cmd: "testing" }, function (data) { alert(data); })
}
(显示警报以适当的值)
我尝试以下:
function test_func() {
return $.post("test.php", { cmd: "testing" }, function (data) { return data; })
}
(返回对象)
function test_func() {
var tmp;
$.post("test.php", { cmd: "testing" }, function (data) { tmp=data; })
return tmp;
}
(返回undefined)
var tmp;
function setTmp(n) {
tmp=n;
}
function test_func() {
t=$.post("test.php", { cmd: "testing" }, function (data) { setTmp(data); })
}
(返回undefined)
function test_func() {
t=$.post("test.php", { cmd: "testing" })
return t.responseText;
}
(返回undefined)
所以,这是怎么回事?我怎样才能让“test_func()”返回数据响应文本?
太棒了,谢谢你的帮助。这是有启发性的。已实施,现在可以使用。 – Gaias 2012-03-13 05:19:56