jquery - Chrome 扩展程序将 POST 请求发送到本地 HTTPS 地址而不是 HTTP
问题描述
我正在构建一个 Chrome 扩展程序,它应该向我的本地站点(Apache Server HTTP 站点)发送一个 POST 请求,但是在尝试执行此操作时出现错误。即使我指定将数据发送到http:// ,它也会将数据发送到https: //
在按钮上单击我调用test2函数。它告诉 AJAX 数据需要发送到特定的 URL。当我单击该按钮时,我收到此错误SSL_ERROR
这是我的 popup.js 代码:
function test2(z,y) {
//makes sure that both parameters are present
if(z)
console.log(z );
if(y)
console.log(y );
//save data from POST in ff variable
ff = $("#frm");
//display all the information gathered from the extension popup, it works fine
console.log(ff);
console.log(ff.attr('id'));
console.log(ff.serialize());
//JQuery Ajax piece of code
$.ajax({
type: 'POST',
dataType:"json",
crossDomain: true,
//this is my local CakePHP website where I want to send data to
url: 'http://land.register/register',
data: ff.serialize(),
method:'post'
}).done(function( data ) {
if ( console && console.log ) {
console.log( "Sample of data:", data );
}
});}
我的land.register\webroot\ .httaccess文件看起来像这样(我没有启用 HTTPS 或为我的本地网站提供证书)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
我的 manifest.json 看起来像这样:
{
"name": "KW Automatische",
"version": "0.1",
"manifest_version": 2,
"description": "Automatyzacja przeszukiwania KW",
"incognito": "spanning",
"content_security_policy": "script-src 'self' 'unsafe-inline' https://ajax.googleapis.com; object-src 'self'",
"browser_action": {
"default_icon": "icon-40@2x.png",
"default_popup": "popup.html",
"default_title": "Click here!"
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["contentScript.js","jquery.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"icons": {
"16": "/images/book.png",
"32": "/images/book.png",
"48": "/images/book.png",
"128": "/images/book.png"
},
"permissions": [
"activeTab",
"http://*/*","*://*/*",
"notifications",
"storage"
]}
解决方案
解决了,我需要<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
从 popup.html 文件中删除。
推荐阅读
- python - 在 Seaborn 中使用 relplot 的标题
- swift - 使用 UIPickerView 时出现约束错误
- javascript - 复制字符串时出现问题,Javascript
- php - 我可以从 htaccess 覆盖扩展目录吗?
- flutter - 如何在 Flutter 中创建 ImageShader?
- node.js - 通过 API 实现的 Passport 本地认证策略
- python - 在 Python 的 Apache Beam 中使用 OrFinally 定义自定义触发器的正确语法?
- php - 如何从字符串日期计算年龄?
- python - 从 csv 输入文件逐行填充一个 excel 文件
- php - Drupal 8:为什么添加 .theme 文件后出现错误?