gpt4 book ai didi

javascript - Jquery [object 对象] 而不是文本

转载 作者:行者123 更新时间:2023-11-28 07:33:07 26 4
gpt4 key购买 nike

我有这段代码,它几乎可以正常工作。问题是,它不是在 div 内显示文本消息,而是打印以下消息: [object Object].. 我使用以下函数浏览了网页并关注了线程:

console.log() 我可以在控制台中看到该消息(感谢 firebug),但我在 div 中看不到它...

我错过了什么?

代码:

$(document).ready(function() {
$("#form_mail").validate({
rules: {
'email': {
required: true,
},
'oggetto': {
required: true,
},
'msg': {
required: true,
},
},
submitHandler: function() {
$.ajax({
type: 'POST',
url: 'mail.php',
data: $('#form_mail').serialize(),
complete: function(html) {
console.log(html);
$('#message').show().text(html).fadeOut(3000, "linear");
}
});
}
});
});

最佳答案

你的问题是,你使用了complete方法而不是success。你在那里得到一个物体的原因是非常明显的。 From documentation :

complete: Function( jqXHR jqXHR, String textStatus ) A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the reques

看到那里了吗?很好。

因此,要使其按预期工作,请将 complete 替换为 success

 success: function(html) {
console.log(html);
$('#message').show().text(html).fadeOut(3000, "linear");
}

关于javascript - Jquery [object 对象] 而不是文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28899982/

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