Get data from mysql database using php and jquery ajax

前端 未结 2 605
Happy的楠姐
Happy的楠姐 2020-12-06 23:22

I want to get data from mysql database using php and jquery ajax. \'process.php\' is the php file which connects to database and get mysql data. It works when it is run sepa

相关标签:
2条回答
  • 2020-12-06 23:45

    There are two syntax errors in your ajax call:

    $(document).ready(function(){
        function showRoom(){
            $.ajax({
                type:"POST",
                url:"process.php",
                data:{action:"showroom"},
                success:function(data){
                    $("#content").html(data);
                }
            });
        }
        showRoom();
    });
    

    Keep in mind that jQuery's ajax expects an object as parameter. Inside an object the syntax is

    { key : value }
    

    You had type="POST" which is correct in declarative syntax, but incorrect when defining an object key.

    Second, the data property of the aforementioned object should be an object too. So instead of action=showroom it should be

    {action:"showroom"}
    
    0 讨论(0)
  • 2020-12-06 23:56

    you did mistake in your code:

     echo "<li>$row['name']</li>";
    

    This should be:

     echo "<li>".$row['name']."</li>";
    

    try that...

    0 讨论(0)
提交回复
热议问题