gpt4 book ai didi

php - 使用 XmlHttpRequest 发出 DELETE 请求

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

大家好,下面是我的代码,我在 setRequestHeaders 行上遇到错误

$(document).ready(function(){
$('#delete').click(function(){
xmlhttp = new XMLHttpRequest();
xmlhttp.open("DELETE","https://server/v0/DTDG78/Test/Tulips.jpg",true);
xmlhttp.setRequestHeader("X-Auth-Token:", "AUTH_tkba87f3f9d9be428898ba362477d18");
xmlhttp.send();
});

});

控制台上的错误消息是

Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.setRequestHeader] [Break On This Error]

...lhttp.setRequestHeader('X-Auth-Token:', 'AUTH_tkba87f3f9d9be428898ba362477d18...

我错过了什么或者根本不可能?任何评论、建议代码表示赞赏。谢谢

最佳答案

如果您使用 jQuery,为什么不让它为您处理 AJAX 调用?

$.ajax({
url: 'https://server/v0/DTDG78/Test/Tulips.jpg',
type: 'DELETE',
async: true,
beforeSend: function( xhr) {
// Note: You probably do not need 'X-Auth-Token:', I've removed the colon
xhr.setRequestHeader("X-Auth-Token", "AUTH_tkba87f3f9d9be428898ba362477d18");
},
success: function( result) {
// TODO
}
});

关于php - 使用 XmlHttpRequest 发出 DELETE 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9156334/

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