我希望使用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