Jump to a hyperlink and execute functions in advance

Source: Internet
Author: User
Before the hyperlink jump, execute the function as the question & nbsp; purpose: click a hyperlink & nbsp; onclick () function to assign a value to the session & nbsp; and then output this value on the page after the jump: why didn't I execute the clicked function & nbsp; no matter whether it returns false or true & nbsp; no value is assigned to the session, the function is executed before the hyperlink jumps.
Example
Objective: to click a hyperlink onclick () function to assign values to the session and then output the value on the page after the jump
Q: Why are I unable to execute the Click link function? no matter whether it returns false or true, it cannot be assigned a value in the session. the page after the jump is blank.
Hyperlink page code


Session_start ();
Function f1 ()
{

$ _ SESSION ['test'] = "wewew ";
Echo "wocaoeo ";
Return false;
}
?>
Click run f1



Page code to jump

Session_start ();
Echo $ _ SESSION ['test'];

?>
 
PHP hyperlink functions:
------ Solution --------------------
Onclick is executed on the client, and php code on the server cannot be executed.
------ Solution --------------------
Onclick can only execute js code. if you want to trigger a php session value, you can trigger an ajax request in onclick to execute php session value initialization, jump to test again based on the ajax request value. php page

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.