JS How to pass the variable to PHP, or JS how to trigger PHP function

Source: Internet
Author: User
Tags what php
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) ~ ~


Reply to discussion (solution)

Using Ajax

Use Ajax, or curl.
The quickest way is to use jquery's $.ajax method.

Use Ajax, or curl.
The quickest way is to use jquery's $.ajax method.


--------------------------------------------------------------

Using Ajax


---------------------------------------------------------------
Excuse me, can you use JS method to call Ajax?

You should look at the basic books. Or download some CHM documents and read about the Jquery.ajax chapter.

You should look at the basic books. Or download some CHM documents and read about the Jquery.ajax chapter.


------------------------------------------------------------------------------------------------------
Is this the only way to crash?

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

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


-------------------------------------------------------------------------------
And then, in some.php, get John through $_post[' name '?

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


-----------------------------------------------------------------------------
What PHP should get is a string, right?
  • Related Article

    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.