I am working with PHP and 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. 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.
Here is an example that calls a PHP script when clicking any image.
$(document).ready(function() {
$("img").click(function() {
$.post("executequery.php");
});
});
In the "executequery.php" you would need to build the SQL and execute it.
Here is the documentation of the method. http://api.jquery.com/jQuery.post/
使用jquery,将ajax调用添加到php脚本中,该脚本应该能够运行插入脚本并返回成功消息。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.