前端开发时报错$.cookie is not a function
实现局部改变的时候会用到ajax
$.ajax({
cache: false,
type: "POST",
url: "/orderManagement/publish_order/",
data: formdata,
async: false,
contentType: false,
processData: false,
datatype: "json",
success: function (data) {
if (data.status_res == "success") {
alert("提交成功!")
window.location.href = "/failureProcess/failure_page/?failure_id={{ alarm.project_id }}"
} else if (data.status_res == "fail") {
alert("提交失败")
}
},
error: function () {
alert("连接失败")
}
结果会报$.cookie is not a function,如果jQuery库文件引用没有问题的话,可能是缺少jquery.cookie.js插件,解决办法:
1、直接引用csdn的插件<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>
2、去官网下载jQuery Cookie,下载1.4.1的
3、如果进不去官网可以去介个地方,提取码:usrv
注意:引用插件之后一定要在ajax参数里加上:headers: {"X-CSRFToken": $.cookie('csrftoken')}
就是下面这样:
$.ajax({
cache: false,
type: "POST",
url: "/orderManagement/publish_order/",
data: formdata,
headers: {"X-CSRFToken": $.cookie('csrftoken')},
async: false,
contentType: false,
processData: false,
datatype: "json",
success: function (data) {
if (data.status_res == "success") {
alert("提交成功!")
window.location.href = "/failureProcess/failure_page/?failure_id={{ alarm.project_id }}"
} else if (data.status_res == "fail") {
alert("提交失败")
}
},
error: function () {
alert("连接失败")
}
})
其他参数按自己的需求修改就ok了。
小白一枚,如有错误请多多指正!!!