大佬教程收集整理的这篇文章主要介绍了jquery – 使用Spring CSRF和ajax Rest调用和带有Thymeleaf的HTML页面,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$(function() { $("#saveCarButton").click( function() { var form = $("#addCarForm"); $.ajax({ type : "POST",url : form.attr("action"),data : form.serialize(),// all right with rest call success : function(data) {...} //error during rest call error : function(data) { window.LOCATIOn.href = "/500"; } }); }); });
一切正常,但当我打电话给这个函数时:
jQuery.ajax({ url : 'upload',type: 'POST',contentType: false,processData: false,data:formData,beforeSend:function(xhr) { waiTingModal.showPleaseWait(); },success: function(data,status,xhr){...} error: function(xhr,E){ } }).complete(function() { //add timeout because otherwise user Could see a too fast waiTing modal setTimeout(function(){ waiTingModal.hidePleaseWait(); },1000); });
我收到错误403.
也许使用形式,使用thymeleaf,它工作正常,但第二种类型的请求我必须添加CSRF令牌.
我试过了
var token = $("Meta[name='_csrf']").attr("content"); var header = $("Meta[name='_csrf_header']").attr("content");
!-- --> <Meta name="_csrf" th:content="${_csrf.token}"/> <!-- default header name is X-CSRF-TOKEN --> <Meta name="_csrf_header" th:content="${_csrf.headerNamE}"/>
为什么表格有效?
我使用表单时不需要添加任何内容?
使用浏览器的开发工具可以看到_csrf和_csrf_header的危险吗?
谢谢
以上是大佬教程为你收集整理的jquery – 使用Spring CSRF和ajax Rest调用和带有Thymeleaf的HTML页面全部内容,希望文章能够帮你解决jquery – 使用Spring CSRF和ajax Rest调用和带有Thymeleaf的HTML页面所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。