gpt4 book ai didi

javascript - 错误函数中的 JQuery AJAX HTML 响应

转载 作者:行者123 更新时间:2023-11-27 23:48:01 24 4
gpt4 key购买 nike

var id = 45;        
$.ajax({
url :'url', // This URL response some HTML content
type: 'POST',
dataType: 'json',
data :{ID:id},
success:function(data)
{
console.log(data); // No Response here
},
error : function (error){
console.log(error); // error.responseText contain html content
}
});

我通过 JQuery AJAX 呈现 HTML 内容。 HTML 响应来自错误函数而不是成功函数。我这边有什么错误吗?

最佳答案

Use html instead of json for datatype

The datatype property specifies the type of data that you're expecting back from the server

$.ajax({
url :'url', // This URL response some HTML content
type: 'POST',
dataType: 'html',
data :{ID:id},
success:function(data)
{
console.log(data); // No Response here
},
error : function (error){
console.log(error); // error.responseText contain html content
}
});

参见 Jquery Api for more details

希望这对您有所帮助。

关于javascript - 错误函数中的 JQuery AJAX HTML 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28718114/

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