How does js pass variables to php, or how does js trigger php functions?

Source: Internet
Author: User
How does js send variables to php, or how does js trigger php functions? in page A. php, we need to count the clicks of each element (image link) on the page and store the clicks. Currently, php interacts with the database. Therefore, you are expected to update the corresponding table in the database after clicking (image link. How can I trigger the php response when I click (image link ~~ ------ Solution -------------- how does js pass variables to php, or how does js trigger php functions?
In page A. php, you need to count the clicks of each element (Image/link) on the page and store the clicks.

Currently, php interacts with the database, so you can update the corresponding table in the database after clicking (Image/link.

How can I trigger the php response when I click (Image/link ~~
------ Solution ----------------------
Use Ajax
------ Solution ----------------------
Use ajax or curl.
The fastest way is to use jquery's $. ajax method.
------ Solution ----------------------
// Give you a demo
// Download jquery. js files.
$. Ajax ({
Type: "POST", // request method
Url: "some. php", // request file
Data: "name = John & location = Boston", // transmission parameters
Success: function (msg ){
Alert ("Data Saved:" + msg); // returned result
}
});
// You can regard ajax as a form request. However, results can be returned 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.