Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用ajax&;从sql中提取我的信息;js,不知道是什么';乌龙_Php_Jquery_Mysql_Ajax_Google Chrome Extension - Fatal编程技术网

Php 使用ajax&;从sql中提取我的信息;js,不知道是什么';乌龙

Php 使用ajax&;从sql中提取我的信息;js,不知道是什么';乌龙,php,jquery,mysql,ajax,google-chrome-extension,Php,Jquery,Mysql,Ajax,Google Chrome Extension,我正在处理一个chrome扩展(刷新),有一个小问题。 我有一个按钮,我希望当按钮被点击时,在我的扩展页面上显示我数据库中的信息 HTML: <button class="button" id="show" style="vertical-align:middle" onclick="myAjax()"><span>Show my purchaes</span></button> <div id="showhere"> //t

我正在处理一个chrome扩展(刷新),有一个小问题。
我有一个按钮,我希望当按钮被点击时,在我的扩展页面上显示我数据库中的信息

HTML:

<button class="button" id="show" style="vertical-align:middle" onclick="myAjax()"><span>Show my purchaes</span></button>
<div id="showhere"> 
    //this is where i want to show the info
</div> 
$(document).ready(function(){
    function myAjax() {
        $.ajax({
            url:"http://127.0.0.1/show.php",
            data:{ action:'showhere' },
            method:"POST",
            success:function(data) {
                ('#showhere').html(data);
            }
        });
    }
}); 
<?php
    if($_POST['action'] == 'showhere') {
        $servername = "localhost";
        $username = "root";
        $password = "********";
        $dbname = "test";

        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        } 

        $sql = "SELECT ProductName, Amount, Date, WebStore FROM budget";
        $result = $conn->query($sql);


        if ($result->num_rows > 0) {
            echo "<table><tr><th>ID</th><th>Name</th></tr>";
            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo "<tr><td>".$row["ProductName"]."</td><td>".$row["Amount"]."</td><td>".$row["Date"]."</td><td>".$row["WebStore"]."</td></tr>";
            }
            echo "</table>";
        } else {
            echo "0 results";
        }

        $conn->close();
    }
?>
PHP:

<button class="button" id="show" style="vertical-align:middle" onclick="myAjax()"><span>Show my purchaes</span></button>
<div id="showhere"> 
    //this is where i want to show the info
</div> 
$(document).ready(function(){
    function myAjax() {
        $.ajax({
            url:"http://127.0.0.1/show.php",
            data:{ action:'showhere' },
            method:"POST",
            success:function(data) {
                ('#showhere').html(data);
            }
        });
    }
}); 
<?php
    if($_POST['action'] == 'showhere') {
        $servername = "localhost";
        $username = "root";
        $password = "********";
        $dbname = "test";

        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        } 

        $sql = "SELECT ProductName, Amount, Date, WebStore FROM budget";
        $result = $conn->query($sql);


        if ($result->num_rows > 0) {
            echo "<table><tr><th>ID</th><th>Name</th></tr>";
            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo "<tr><td>".$row["ProductName"]."</td><td>".$row["Amount"]."</td><td>".$row["Date"]."</td><td>".$row["WebStore"]."</td></tr>";
            }
            echo "</table>";
        } else {
            echo "0 results";
        }

        $conn->close();
    }
?>

我想让它做的很简单:我有一个按钮,下面有一个div,名为:“showhere”,在这个div中,我想获取mysql信息并编写它。 我没有写确切的问题,问题是按钮什么都不做


阿甘,谢谢

我建议您这样设置:

$(文档).ready(函数(){
$('#show')。在('click',函数(e){
e、 预防默认值();
$.ajax({
url:“http://127.0.0.1/show.php",
数据:{
行动:“展示在这里”
},
方法:“张贴”,
成功:功能(数据){
(#showhere').html(数据);
}
});
});

});到底是什么问题?如果此按钮位于扩展工具栏图标的弹出窗口内,则不允许使用类似
onclick=“myAjax()”
的内联js。使用一个单独的js文件和适当的事件监听器。请将问题放在主题上:包括一个复制问题的完整文件。通常,包括manifest.json、一些后台脚本和内容脚本。寻求调试帮助的问题(“为什么此代码不工作?”)必须包括:►想要的行为,►特定的问题或错误,以及►在问题本身中复制它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:“如何创建”,以及.raymond thx,但它仍然不起作用,问题是当我单击按钮时,什么也没有发生。