gpt4 book ai didi

PHP 和 Jquery 的 json

转载 作者:搜寻专家 更新时间:2023-10-31 20:55:15 25 4
gpt4 key购买 nike

我的 html 文件:

    <script>
$(document).ready(function() {
$.ajax({
type: "POST",
url: "search.php",
data: "id=1",
datatype: "json",
success: function(msg){
$('.result1').html(msg["name"]);
}
});
})
</script>

<span class="result1"></span>

我的 php 文件:

    <?
$a["name"] = 'john';
echo json_encode($a);
?>

为什么 John 这个名字没有出现在 result1 类中?为什么?请帮助我,我快疯了。

编辑:现在是否可以悬赏?

最佳答案

dataType 参数有一个大写字母 T。如果您更正它,它就会起作用。

目前(默认情况下)尝试根据 mime 类型猜测响应格式,因此可能默认为 html - 在 firebug 中调试你可以看到成功回调的 msg 参数是包含 JSON 的字符串。

关于PHP 和 Jquery 的 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3387738/

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