我如何在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"});