报错 POST http://192.168.79.165:8015/marketing/manager 400 (BAD REQUEST) 解决办法

我用jQuery ajax post方法 用flask url_for 传值到后端

$.ajax({
	url:"{{url_for(‘marketing.manager‘)}}",
	type:‘post‘,
	dataType:‘json‘,
	// data:params,
	data:{‘params‘:‘aResult‘},
	success:function(data){
		// console.log(data)
		console.log(‘success‘)
	},error:function(xhr){
		// console.log(xhr)
		console.log(‘fail‘)
	}
})

结果出问题了 报出错误 POST http://192.168.79.165:8015/marketing/manager 400 (BAD REQUEST)

----------------------------------------------------------------------------------------------------------------------------------------------------以上是问题

网上找的网址 https://segmentfault.com/q/1010000004019749/a-1020000004020013

发现问题确实是 后端用了CRSF 前端应该在ajax中加上一个关于crsf的东西

var csrf_token = "{{ csrf_token() }}";
$.ajax({
	url:"{{url_for(‘marketing.manager‘)}}",
	beforeSend: function(xhr, settings) {
		if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
			xhr.setRequestHeader("X-CSRFToken", csrf_token);
		}
	},
	type:‘post‘,
	dataType:‘json‘,
	// data:params,
	data:{‘params‘:‘aResult‘},
	success:function(data){
		// console.log(data)
		console.log(‘success‘)
	},error:function(xhr){
		// console.log(xhr)
		console.log(‘fail‘)
	}
})

附上解决代码链接:csrf protection

--------------------------------------------------------------------------------------------------------------------------------------------------------------解决

PS:不过后端一直踩坑 POST,GET不要随意大小写哦~都是泪

时间: 2024-11-05 09:22:48

报错 POST http://192.168.79.165:8015/marketing/manager 400 (BAD REQUEST) 解决办法的相关文章

Mysql远程登录报错:Host '192.168.1.3' is not allowed to connect to this MySQL server

你要访问的MySQL服务器设置了访问权限:如果那个服务器是你自己搭建的解决办法如下,但如果不是你的请管理员帮你添加权限 解决办法1: # 1. 改表 # 登录数据库:mysql -u root -p mysql>use mysql; mysql>update user set host = '%' where user = 'root'; mysql>FLUSH PRIVILEGES; 2. 授权法. (1)例如,你想myuser使用mypassword从任何主机连接到mysql服务器的

MSSQL报错:参数数据类型 text 对于 replace 函数的参数 1 无效的解决办法

Ms - sql 数据库批量替换字符串 MSSQL报错:参数数据类型 text 对于 replace 函数的参数 1 无效的解决办法 update ContentInfo set spcContent=replace(cast(spcContent as varchar(max)),'http://www.buy5188.com/','http://www.epowerchina.com.cn/')

appium===报错Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.的解决办法

要解决的问题:appium在androidV7.0系统上运行时报错 Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.] 原因分析:appium的uiautomator版本与androidV7.0不适配. 预置条件:手机端已经安装完Appium Settings 和 Unlock两个应用 解决步骤:1.修改源码文件-注释安装appi

免安装版--- mysql 启动报错--发现系统错误2,系统找不到指定的文件。解决办法

HKEY_LOCAL_MACHINE-SYSTEM-CurrentControlSet-services-mysql(服务名)-ImagePath 更改为:"C:\Program Files\MySQL\bin\mysqld" --defaults-file="C:\Program Files\MySQL\my.ini" mysql 以上为参考实例改为安装mysqld的实际路径

解决Zookeeper报错:conf is not executed because it is not in the whitelist的解决办法

1.echo wchp | nc localhost 2181 ,通过路径列出服务器 watch 的详细信息,且它会输出一个与 session 相关的路径.但是出现下面的错误. [[email protected] conf]# echo wchp | nc localhost 2181 wchp is not executed because it is not in the whitelist. 2.cd /usr/local/zookeeper/conf下,用vim打开zoo.cfg,在最

【转】ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.165' (113)

原文转自:http://blog.csdn.net/chengyuqiang/article/details/54285857 1.程序报错: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link 2.尝试远程连接数据库: [[email protected] ~]# mysql -h192.168.1.165 -uroot -p123456 ERROR 2003 (HY000): Can't c

谷歌浏览器报错:跨域问题处理( Access-Control-Allow-Origin)_ 用于本地测试的快捷解决方法

报错提示如下: XMLHttpRequest cannot load http://www.xxxx.com/264/Data/GetScreenInfo. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 今天需要做一个本地测试,html中的js效果涉及跨域拉取数据的问题,Chrome报错并拒绝数

@(报错)could not find the main class, Program will exit(已解决)

原文 @(报错)could not find the main class, Program will exit(已解决) (很抱歉,如果你希望能更加清楚地看清图片或是图上的文字的话,你可以按住ctrl不动,然后向上滚动鼠标的滚轮.要改变回来同理向下滚动即可.) -------------------------------------------------------------------- 今天2011.4.20: 这篇文章是我刚接触myeclipse的时候写的,一年过去了,感觉自己成熟

【Android】Android import和export使用说明 及 export报错:jarlist.cache: Resource is out of sync with the file syst解决

在Android开发export项目时发现有时会报错,内容如下: Problems were encountered during export:  Error exporting PalmIdentify/bin/jarlist.cache: Resource is out of sync with the file system: '/PalmIdentify/bin/jarlist.cache'.    Resource is out of sync with the file syste