使用本地数据库中的数据填充Google扩展程序

时间:2013-12-12 09:34:52

标签: javascript sql database google-chrome google-chrome-extension

======================的manifest.json ====================== ====

{
  "manifest_version": 2,

  "name": "URL pins",
  "description": "",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "http://localhost/pinterest/extension.php"
  ]
}

==================== popup.js ======================

<script type="text/javascript" language="javascript">
function checkusername(){
    var status = document.getElementById("plugin");
    var hr = new XMLHttpRequest();
    hr.open("GET", "http://localhost/pinterest/extension.php", true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            status.innerHTML = hr.responseText;
        }
    }
    hr.send();
}
}
</script>

======================= popup.html ===================== =====

<!doctype html>
<html>
  <head>
    <title>Getting Started Extension's Popup</title>
    <style>
      body {
        min-width: 357px;
        overflow-x: hidden;
      }

      img {
        margin: 5px;
        border: 2px solid black;
        vertical-align: middle;
        width: 75px;
        height: 75px;
      }
    </style>

    <!--
      - JavaScript and HTML must be in separate files: see our Content Security
      - Policy documentation[1] for details and explanation.
      -
      - [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
     -->
    <script src="popup.js"></script>
  </head>
  <body>
  <div id="plugin"></div>
  </body>
</html>

============= entension.php ========================

<?php
session_start();
include 'database.php';
    $uid=$_SESSION['user']['id'];
    $string = '<input type="text" name="url" id="url" placeholder="URL...."><br>';
    $result = mysql_query("select * from board where userid='$uid'",$con);
    $string .="<select name='board'>";
    while ($row = mysql_fetch_assoc($result)) {
                unset($id, $name);
                  $id = $row['boardid'];
                  $name = $row['boardname']; 
                  $string .= '<option value="'.$id.'">'.$name.'</option>';

    }
    $string .= "</select></br>";
    echo $string;
    exit();

?>

我正在尝试获取用户在数据库中创建的所有主板并将其弹出Chrome扩展程序 当我点击扩展名时,我看到空弹出窗口,但是当我在浏览器中运行extension.php时,它会显示预期的输出。 我是google扩展程序的新用户可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

您没有将checkusername()函数绑定到任何事件,因此它永远不会被执行 要解决此问题,请将以下行添加到popup.js

document.addEventListener('DOMContentLoaded', function() {
    checkusername();
});

BTW,调试此类问题:

  • 右键单击浏览器操作按钮,然后选择“检查弹出窗口”。
  • 在打开的“开发者工具”面板中,转到Network标签。
  • 检查与弹出相关的代码发出的任何请求(请求/响应标头,响应正文等)。

<子> (虽然“开发人员工具”面板保持打开状态,但弹出窗口也是如此,因此您可以在调试时与其他窗口/面板进行交互。)


顺便说一下,你的}还有一个额外的popup.js(也没有任何帮助)。

相关问题