我用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不要随意大小写哦~都是泪

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

  1. npm install 报错 error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,"d' 解决办法

    npm install 报错 : error Unexpected end of JSON input while parsing near '...sShrinkwrap":false,& ...

  2. 批量改主机名报错:Address 192.168.43.117 maps to bogon, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

    ssh连接批量修改主机名报出以下提示: [root@bqh-nfs- ~]# vim modfilyhostname.sh [root@bqh-nfs- ~]# sh modfilyhostname. ...

  3. pip安装pycrypto报错:Microsoft Visual C++ 14.0 is required. 和 SSLError: HTTPSConnectionPool的解决办法

    今天本打算把[Python3爬虫]网易云音乐爬虫 的代码敲一遍, 但是在安装pycrypto老是报错, 由于我计算是win10, 并且也有vs2017 python3环境下安装pycrypto的一些问 ...

  4. 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.a ...

  5. Web 项目报错No suitable driver found for jdbc:mysql://localhost:3306/book 的一个解决办法

    确认jar包加入到了build path中,然后注意版本是否与数据库相配,还要留意将jar包放入WEB-INF下的lib文件夹中

  6. 报错 Inferred type 'S' for type parameter 'S' is not within its bound; 解决办法

    出现情况: Inferred type 'S' for type parameter 'S' is not within its bound; should extends xxxxxx 出现这种问题 ...

  7. appium===报错adb server version (31) doesn’t match this client (39); killing…的解决办法

    当使用在cmd窗口调用adb shell命令的时候 提示如下: adb server version (31) doesn't match this client (39); killing...er ...

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

    1.echo wchp | nc localhost 2181 ,通过路径列出服务器 watch 的详细信息,且它会输出一个与 session 相关的路径.但是出现下面的错误. [root@xg61 ...

  9. 【转】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.jd ...

随机推荐

  1. Python运维开发基础08-文件基础

    一,文件的其他打开模式 "+"表示可以同时读写某个文件: r+,可读写文件(可读:可写:可追加) w+,写读(不常用) a+,同a(不常用 "U"表示在读取时, ...

  2. android 读取json数据(遍历JSONObject和JSONArray)(转)

    public String getJson(){ String jsonString = "{\"FLAG\":\"flag\",\"MES ...

  3. Android开发之通过包管理器获取安装应用信息

    最近在自己写一个APP,有一个模块需要获取手机应用的一些信息.坑还是有,但都基本踩过了,自己把他实现了出来,实现方法还是很需要掌握的.底部弹出的对话框中四个选项的实现不多做说明,主要讲讲如何获取这些安 ...

  4. jQuery的基本事件

    1.用法 <!--jquery通过bind()这个方法来为元素绑定事件,可以传三个参数,type.data.fn--> <!--type表示一个或者多个事件的名称--> < ...

  5. std::time(0)找不到

    http://zh.cppreference.com/w/cpp/chrono/c/time #include <ctime> isnan找不到 http://en.cppreferenc ...

  6. Android使用ListView使用方法

    Android使用ListView应该注意的地方   在ListView中设置Selector为null会报空指针? mListView.setSelector(null);//空指针 试试下面这种: ...

  7. Executing a Finite-Length Task in the Background

    [Executing a Finite-Length Task in the Background] Apps that are transitioning to the background can ...

  8. windows server2012怎样关机怎样重启-详细教程

    | 浏览:1991 | 更新:2014-12-15 17:33 1 2 3 4 5 6 分步阅读 百度经验:jingyan.baidu.com windows server2012和以往有些不同,关机 ...

  9. 团体程序设计天梯赛L2-023 图着色问题 2017-04-17 09:28 269人阅读 评论(0) 收藏

    L2-023. 图着色问题 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 图着色问题是一个著名的NP完全问题.给定无向图 G ...

  10. 有關更新Java 至UPDATE 45 後出現沒法進入ORACLE EBS

    近日部份使用者在更新Java 至UPDATE 45 後出現沒法進入ORACLE.  解決方法如下. 在開始 => 程式集 => JAVA => Configure Java中 (Ja ...