JS How to pass a variable to PHP, or how JS triggers php functions

Source: Internet
Author: User
JS How to pass the variable to PHP, or JS how to trigger PHP function
In page a.php, you want to count the number of elements (picture/link) clicks in the page and store the clicks.

PHP is currently interacting with the database, so I want the user to click (Image/Link), PHP can react, to update the database in the corresponding table.

Excuse me, what method can I use to trigger the reaction of PHP when I click (Picture/link) ~ ~
------to solve the idea----------------------
Using Ajax
------to solve the idea----------------------
Use Ajax, or curl.
The quickest way is to use jquery's $.ajax method.
------to solve the idea----------------------
I'll give you a demo.
Need to download a jquery.js
$.ajax ({
Type: "POST",//Request method
URL: "some.php",//Request file
Data: "Name=john&location=boston",//parameters of the transmission
Success:function (msg) {
Alert ("Data Saved:" + msg);//Returns the result
}
});
Ajax can be seen as a form request. But you can return the results in real time
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.