问题描述
我正在使用PHP向数据库提交非常简单的数据.在我的page.php上,我有一个链接,通过单击它,可以在数据库中插入其ID和其他一些数据.例如:
I'm using PHP to submit a very simple data to db. On my page.php, I have a link, by clicking it I insert its id and some other data in the database. For example:
echo "<a href='".$base_url."?submit=$page_id'> Submit it</a>";
它生成类似于page/test-page/?submit = 12的url
It generates the url like page/test-page/?submit=12
在页面顶部,我获得带有$ _GET的页面ID,并通过以下方式将其插入到数据库中:
On the top of the page I get the page id with $_GET and insert it to the db in the following way:
if (isset($_GET["submit"])) {
$page_id = $_GET['submit'] //yes, its not secure.
//insert in db.
//get db success/error msg in $db_msg
}
如何在不刷新页面的情况下提交数据并获得数据库成功或失败消息.
How can I submit the data and get the database success or fail message without refreshing the page.
推荐答案
查阅有关Ajax函数的JQuery文档: http://api.jquery.com/jQuery.post/
check out the JQuery Documentation about Ajax Functions: http://api.jquery.com/jQuery.post/
你会做类似的事情
$.ajax({
type: 'POST',
url: page.php,
data: submit=$page_id,
success: function(){print("success");}
});
btw:使用post比获取更好,它看起来更干净. (至少在我看来)
btw: it is better to use post than get, it just looks cleaner. (at least in my opinion)
这篇关于如何使用jQuery发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!