简体   繁体   English

在单击INSERT INTO mySQL而不更新当前页面

[英]On click INSERT INTO mySQL without updating the current page

I am working with PHP and mySQL. 我正在使用PHP和mySQL。 On page1.php there will be an image that when the user clicks on it there will be a query that inserts into mysql some data. page1.php上将有一个图像,当用户单击它时,将有一个查询将一些数据插入mysql。 How can I do this without reloading the page or transferring the user someone else and change the image? 如何在不重新加载页面或不向用户转移其他人并更改图像的情况下执行此操作?

What I did so far is to do this but with reloading the page. 到目前为止,我要做的就是重新加载页面。

Thanks for your ideas/examples. 感谢您的想法/示例。

It is as simples as executing the post method of jQuery library. 它就像执行jQuery库的post方法一样简单。

Here is an example that calls a PHP script when clicking any image. 这是一个在单击任何图像时调用PHP脚本的示例。

$(document).ready(function() {
    $("img").click(function() {
        $.post("executequery.php");
    });
});

In the "executequery.php" you would need to build the SQL and execute it. 在“ executequery.php”中,您将需要构建SQL并执行它。

Here is the documentation of the method. 这是该方法的文档。 http://api.jquery.com/jQuery.post/ http://api.jquery.com/jQuery.post/

使用jquery,将ajax调用添加到php脚本中,该脚本应该能够运行插入脚本并返回成功消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM