我如何在PHP和Jquery的帮助下使用chrome扩展与我的数据库进行交互
How do I interact with my database using a chrome extension with the help of PHP, and Jquery?
我想引起数据库的变化,我有使用chrome扩展。我试图使用AJAX链接PHP页面的查询到弹出窗口。html页面,但它仍然不工作。该页面是工作良好时,独立使用,但不作为chrome扩展。我犯了什么错误?
这是我使用的myScript.js文件:
$("document").ready(function(){
$("#save").click(function(){
alert("Clicked");
var jxhr= $.ajax("save.php");
//doSomething();
jxhr.done(function(){alert("Complete");});
});
$("#shareu").click(function(){
// alert("shared");
$.ajax({
url: "share_with_user.php"});
});
$("#shareg").click(function(){
// alert("showing Groups");
$.ajax({
url: "edit_page.php"});
});
$("#show").click(function(){
// alert("showing Links");
$.ajax({
url: "display.php"});
});
});
这是我用来更新数据库的php文件。
<?php
if (empty($errors)) {
// Perform Update
$query="INSERT INTO LINKS (USER_ID, LINK) VALUES (";
// $query.=$_SESSION['userID'];
$query.="2 ,";
$query.="'WWW.GOOGLE.COM' ";
$query.=");";
$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) == 1) {
// Success
echo "Awesome";
$_SESSION["message"] = "Page updated.";
} else {
// Failure
$_SESSION["message"] = "Page update failed.";
}
}
?>
<?php include("header.php"); ?>
<div>
Display Page
</div>
<?php include("footer.php"); ?>
如果还需要其他信息,请告诉我。
感谢编辑1:Picker.html(弹出式文件)
<html>
<head>
<title>Pump!- Share your URLs</title>
<link rel="stylesheet" type="text/css" href="mystyles.css">
</head>
<body>
<h1>URL Recognised!</h1>
<button id="save">Save to own Links</button></br>
<button id="shareu">Share with 1 user</button></br>
<button id="shareg">Share with Groups</button></br>
<button id="show">Show Links</button>
<div id="update"></div>
<script src="jquery.js" type="text/javascript"></script>
<!-- <script src="pumpapp.js" type="text/javascript"></script>
--><script src="myScript.js" type="text/javascript"></script>
</body>
</html>
Manifest文件:Manifest .json
{
"manifest_version":2,
"name" : "Pump",
"description": "Just to add the page"
,
"version":"1.0",
"browser_action":{
"default_icon":"icon.png",
"default_popup":"picker.html"
},
"content_scripts": [
{
"matches": ["http://*/*"],
"css": ["mystyles.css"],
"js": ["jquery.js", "myScript.js"],
"all_frames":true
}
]
}
您正在发出相对于扩展源的ajax请求。您需要显式地设置服务器的URL。
$.ajax({url: "share_with_user.ph"});
应该是这样的:
$.ajax({url: "https://exapmle.com/share_with_user.php"});
相关文章:
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 试图阻止Chrome通过扩展关闭
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 从选项页面更新chrome扩展清单权限
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- Chrome扩展:遍历不同的页面并收集数据
- Chrome扩展 chrome.storage 如何同时进行大量获取和设置并避免竞争条件
- Chrome扩展:Chrome.tabs.executeScript不工作
- 中的访问扩展chrome://extensions页
- 如何在扩展Chrome DevTool时检索请求的启动器
- Chrome扩展-Chrome报警API为创建的每个新报警重新安排所有报警
- 是否有任何方法来扩展chrome's __commandLineAPI
- 谷歌Chrome扩展Chrome .tab . onupdate . addlistener
- 创建在页面上注入脚本的扩展chrome内容
- Chrome扩展:Chrome扩展中未定义的变量,即使它存在于控制台中