Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryajax';toLowerCase';基本POST方法出错,但适用于类似的删除方法_Jquery_Ajax - Fatal编程技术网

jqueryajax';toLowerCase';基本POST方法出错,但适用于类似的删除方法

jqueryajax';toLowerCase';基本POST方法出错,但适用于类似的删除方法,jquery,ajax,Jquery,Ajax,我试图做一个基本的帖子,但我得到了一个“toLowerCase”错误 我的URL是“developer/58ace2b191e01c24f61fc241/Break” 请求是“”,但由于某种原因,这不起作用 broke = function (url) { var request = getRootUrl() + url; var token = $("meta[name='_csrf']").attr("content"); var header = $("meta[name='_csrf_h

我试图做一个基本的帖子,但我得到了一个“toLowerCase”错误

我的URL是“developer/58ace2b191e01c24f61fc241/Break” 请求是“”,但由于某种原因,这不起作用

broke = function (url) {
var request = getRootUrl() + url;
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(e, xhr, options) {
    xhr.setRequestHeader(header, token);
});
$.post(request, function(data) {
    console.log("hit");
});
};
但是,我有一种非常类似的删除方法,它确实有效:

makeDeleteCall = function (url) {
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(e, xhr, options) {
    xhr.setRequestHeader(header, token);
});
$.ajax({
    type: "DELETE",
    url: getRootUrl() + url
});
};
完整堆栈跟踪:

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
at Object.setRequestHeader (http://localhost:8080/js/jquery.js:4:19436)
at HTMLDocument.<anonymous> (http://localhost:8080/js/developer.js:22:13)
at HTMLDocument.dispatch (http://localhost:8080/js/jquery.js:3:8436)
at HTMLDocument.m.event.add.r.handle (http://localhost:8080/js/jquery.js:3:5139)
at Object.trigger (http://localhost:8080/js/jquery.js:3:7537)
at Function.ajax (http://localhost:8080/js/jquery.js:4:21187)
at Function.m.each.m.(anonymous function) [as post] (http://localhost:8080/js/jquery.js:4:22297)
at broke (http://localhost:8080/js/developer.js:24:7)
at HTMLTableCellElement.onclick (http://localhost:8080/newDev:58:136)
Uncaught TypeError:无法读取未定义的属性“toLowerCase”
在Object.setRequestHeader(http://localhost:8080/js/jquery.js:4:19436)
在HTMLDocument。(http://localhost:8080/js/developer.js:22:13)
在HTMLDocument.dispatch(http://localhost:8080/js/jquery.js:3:8436)
在HTMLDocument.m.event.add.r.handle(http://localhost:8080/js/jquery.js:3:5139)
在Object.trigger(http://localhost:8080/js/jquery.js:3:7537)
在Function.ajax(http://localhost:8080/js/jquery.js:4:21187)
at Function.m.each.m.(匿名函数)[as post](http://localhost:8080/js/jquery.js:4:22297)
破产(http://localhost:8080/js/developer.js:24:7)
在HTMLTableCellElement.onclick(http://localhost:8080/newDev:58:136)

那么,为什么这对一个ajax调用(DELETE)有效,而对另一个ajax调用(POST)无效呢?

页面上的csrf标记不是这样设置的:

    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header" th:content="${_csrf.headerName}"/>


但在“删除”按钮起作用的页面上,它们被设置了。因为它们没有定义,所以导致jQuery崩溃。

在代码中的什么地方使用了
toLowerCase
?您是否尝试过与DELETE相同的方法。我的意思是使用$.ajax而不是$.post