嗨,大家好,下面是我的代码,我在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();
});
});
控制台上的错误消息是
组件返回的失败代码:0x80004005(NS_ERROR_FAILURE)[nsIXMLHttpRequest.setRequestHeader] [中断此错误]
... 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
}
});