gpt4 book ai didi

PHP ajax成功: function (msg) - get msg

转载 作者:行者123 更新时间:2023-12-01 08:23:57 25 4
gpt4 key购买 nike

我有一些 jquery/php 代码,它使用 ajax 调用另一个页面。

var pall_id = $(this).attr('id');
$.ajax({
type: "POST",
url: "do_history.php?pall_id="+pall_id,
success: function (msg) {
alert (msg);

},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert('Error submitting request.');
}
});

但是我该怎么做才能获取 msg 的值呢?例如如果 do_history.php 只是:

<?php

$text="text";
return $text;

?>

“msg”不会是“文本”,所以当我警告(msg)时;我的屏幕上会弹出“文本”。

我需要做什么才能返回字符串值?有什么想法吗?

谢谢

最佳答案

使用 echo $text; 并在 $.ajax 选项中添加 dataType: 'text'

但是,更好的解决方案是使用 dataType: 'json',然后使用 echo json_encode($text); - 在本例中是 $text 也可以是数组/对象/数字,并且它是 JavaScript 函数中的适当类型.

关于PHP ajax成功: function (msg) - get msg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5421614/

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