send data to MySQL with AJAX + jQuery + PHP

后端 未结 6 2081
天涯浪人
天涯浪人 2020-12-09 13:58

I\'ve been looking all day to find a way to insert some data into my database and then show the new data in the list of already existent data on my webpage.

I know t

6条回答
  •  离开以前
    2020-12-09 14:29

    You can send anything in that property. Try this: js

    $.ajax({
        url: "messages.php",
        type: "POST",
        data: 'show=content',
        success: function(data) {
            $('#output').html(data);    
        },  
    });
    

    messages.php

    if(isset($_POST['show']) && $_POST['show']=='content') {
     // rest of your code goes here..
    }
    

    One more thing. Use MySQLi instead of MySQL as it's a deprecated extension now.

提交回复
热议问题