使用PHP将段落存储到数据库中而不刷新页面

使用PHP将段落存储到数据库中而不刷新页面,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我有一个index.php页面,其中包含一个段落元素和一个输入按钮: <p id="result">Hello this is test paragraph</p> <input id="insertbutton" type="button" value="insert" /> 您好,这是测试段落 我想在单击“插入”按钮时将段落内容存储到数据库中,而不刷新页面 希望我能得到帮助 非常感谢您将Ajax与jQuery结合使用来发出这样的post请求就足

我有一个index.php页面,其中包含一个段落元素和一个输入按钮:

<p id="result">Hello this is test paragraph</p>    
<input id="insertbutton" type="button" value="insert" />

您好,这是测试段落

我想在单击“插入”按钮时将段落内容存储到数据库中,而不刷新页面

希望我能得到帮助


非常感谢您

将Ajax与jQuery结合使用来发出这样的post请求就足够了

$("#insertbutton").click(function(){
    var data = "text=" + $("#result").text();
    $.ajax({
        type: "POST",
        url: "post.php",
        data: data,
        success: function(){
            alert("success");
        }
    });
});

使用javascript的ajax或jQueryYou必须阅读有关insertbutton是选择器的内容,使用#这对我很有帮助,但它是插入空记录。这是我的php代码:$_POST['data']应该是$_POST['text'],而不是更改php代码,您可以更改Javascript并将“text”字符串替换为“data”:var data=“data=”+$(“#result”).text();你是伴郎,非常感谢!它现在正在输入记录
<p id="result">Hello this is test paragraph</p>

<input id="insertbutton" type="button" value="insert" />
$("#insertbutton").click(function(){
var dataToPass=$("#result").html();

$.ajax({
url:'Your_PHP_File_URL_that_will_do_insertion',
data:dataToPass
});
})