gpt4 book ai didi

php - 在 jQuery 函数中获取结果 PHP 代码?

转载 作者:行者123 更新时间:2023-11-28 16:24:09 25 4
gpt4 key购买 nike

我使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com