我使用codeigniter,我想用php制作uniqid代码,如下代码(通过random_string()):
function coding(){
echo random_string('unique');
}
我想在 jquery 函数中使用结果顶部函数(用于 js 代码),我在 jquery 代码中尝试这样做,但是 alert(coding())
中的输出是“未定义” ”。如何解决?
function coding(){
$.ajax({
type: "POST",
dataType: "text",
url: "coding",
cache: false,
success: function (data) {
return data;
}
})
}
alert(coding()) // in here output is "undefined" !!!?
最佳答案
function coding(){
var temp;
$.ajax({
type: "POST",
dataType: "text",
url: coding,
cache: false,
async: false,
success: function (data) {
temp = data;
}
})
return temp;
}
alert(coding());
您将收到一个[object XMLDocument]。
关于php - 在 jQuery 函数中获取结果 PHP 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8585876/