版权声明

  • 本文原创作者:谷哥的小弟
  • 作者博客地址:http://blog.csdn.net/lfdfhl

问题描述

在利用表单向后台提交数据时,前端页面报错:

Refused to execute inline script because it violates the following Content Security Policy directive: “default-src ‘self’”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-2/nwTfnmhsEOQ+pVDGpNeMyOzp4HRtQri8QvvBb+A6Q=’), or a nonce (‘nonce-…’) is required to enable inline execution. Note also that ‘script-src’ was not explicitly set, so ‘default-src’ is used as a fallback.

解决方案

在前端表单提交时请勿采用type="submit"的方式,而应采用type="button"

示例代码

在此,以示例形式展示解决方案。

html代码

<form method="post" id="userform2">姓名: <input type="text" id="name" name="username" style="width: 150px" /><br /><br />年龄: <input type="text" id="age" name="userage" style="width: 150px" /><br /><br /><input id="ajaxPostButton4" type="button" value="利用$.post()提交表单" />
</form>

JavaScript代码

//利用$.post()提交表单
$("#ajaxPostButton4").click(function() {var url = "http://xxx.xxx.137.1:8080/MyController/test";var params = $("#userform2").serialize();console.log(params);$.post(url,params,function(data) {console.log(data);},"json");
});

Refused to execute inline script because it violates the following Content Security Policy directive相关推荐

  1. because it violates the following Content Security Policy directive: “default-src ‘none‘“

    在打开页面时浏览器报如下错误: Refused to load the script 'http://xx.xx.xx.xx:xxxxx/livereload.js?snipver=1' becaus ...

  2. Vue打包后出现的bug -favicon.ico' because it violates the following Content Security Policy direc

    打开vue的项目,但是页面显示的是Cannot GET,打开控制台之后,发现有一篇红色报错. //Refused to load the image 'http://localhost:8080/fa ...

  3. violates Content Security Policy报错1

    index.html:1 Refused to load the script 'https://webapi.amap.com/maps?v=1.4.13&key=b7063c0343460 ...

  4. Electron中提示:Refused to execute inline event handler because it violates

    场景 在Electron中点击index.html中的button按钮时想要其触发renderer.js的方法. 在index.html中 <button onclick="getPr ...

  5. Refused to load the image 'URL' because it violates the following content security polity diretive

    转载地址:https://www.cnblogs.com/xiaoxiaoluoye/p/6945044.html 深入学习地址:https://www.cnblogs.com/Hwangzhiyou ...

  6. Discourse Refused to load the script 错误

    Discourse 在运行的时候提示有 JS 错误. 错误如下: Refused to load the script 'https://www.ossez.com/cdn-cgi/apps/head ...

  7. uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec

    报错原因 整体流程的话,就是将网页通过 web-view 组件内嵌到 App 中(非小程序),其中有跳转微信公众号的需求,不料却收到了以下报错. 我又不是打包小程序,就套壳个 App ,比较疑惑为什么 ...

  8. Refused to execute script from ‘「URL」‘ because its MIME type (‘text/html‘) is not executable

    项目使用spring security进行认证和权限控制 jQuery要在bootstrap前面引用 <script th:src="@{/js/jquery-3.3.1.min.js ...

  9. Refused to execute script from ‘http://localhost:8080/src/23-namespace/a.js‘ because its MIME type (

    谁知道这个问题怎么解决吗? ![在这里插入图片描述](https://img-blog.csdnimg.cn/ec7f9c0

最新文章

  1. C语言科学计算器思路,大神教你如何用C语言实现科学计算器
  2. Win2003服务器设置防火墙图文教程
  3. 【Paper】41_[24]novel type of phase transition in a system of self-driven particles
  4. matlab pdist
  5. python云计算开发技术_云计算开发学习笔记:Python3 面向对象技术简介
  6. elementUI 分页组件的使用 - 踩坑篇
  7. oracle 创建表空间 pcincrease,oracle建表空间
  8. Java 数据结构之双链表
  9. Logistic Regression分类器与softmax分类器
  10. 写了一个3D彩票软件!
  11. mac版ps快捷键大全
  12. MagicDraw-BDD图
  13. 自媒体文章如何有效提高原创度?
  14. linux 4g 切换 有线网,4G和有线网络的自动切换
  15. 小小知识点(十九)护眼色豆沙绿的设置
  16. 真正优秀的人,更懂得尊重别人
  17. 嵌入式系统框架----硬件篇
  18. LY3006A手电筒集成IC可充电多功能 LED 驱动控制芯片
  19. 自媒体视频如何消重?批量处理去重消重去水印去logo软件企鹅号视频不重复必学的消重技巧...
  20. java静态方法详解

热门文章

  1. C/C++编程:reference to non-static member function must be called
  2. iOS之网络下载文件
  3. linux开组态软件,基于嵌入式Linux的组态软件实时数据库的设计
  4. CTFHub-web前置技能-请求方式、302跳转、cookie、基础认证、响应包源代码
  5. ZYNQ基本用法------DDR(1)
  6. ALTER TABLE 语句与 FOREIGN KEY 约束“FK_Booking_Hotel“冲突。
  7. win7更新_微软最新累积更新导致Win7及以上版本VB6/VBA/VBS运行异常
  8. 还在找icon吗,这里有你想要的一切!!!
  9. REVERSE-COMPETITION-HGAME2022-Week3
  10. 如何设置Python环境变量?