How to pass variables between pages

Source: Internet
Author: User
Tags form post php session
{Code ...} I uploaded $ mes to another php page: & amp; lt; script & amp; gt; document. write (a) & amp; lt; script & amp; gt;, unable to be called, workhard.


《script》var test = [ "1", "2", "3", "4", "5", "6"];var a = test[Math.floor(Math.random() * test.length)];document.write(a);《script》

I uploaded $ mes to another php page, which is《script》document.write(a)《script》And cannot be called.

Reply content:


《script》var test = [ "1", "2", "3", "4", "5", "6"];var a = test[Math.floor(Math.random() * test.length)];document.write(a);《script》

I uploaded $ mes to another php page, which is《script》document.write(a)《script》And cannot be called.

For multi-page applications.
Then you canquerystringTo output the variable to the front end.
http://url/a?key=value
For a single page application, we recommend that you use the History API
pushState popStateAndreplaceState

There are two transmission methods

First, the explicit

Passed through url query string, as shown in figureHttp://dict.youdao.com/search? Q = China, WhereqThat is, the passed parameter.

Second, implicit

Pass through the SESSION in PHP, the content to be passed is saved in the php session in advance, jump to the page and let the subsequent page get the value in the SESSION.

Php:
$ _ GET is an array of variables passed to the current script through URL parameters.
$ _ POST is an array of variables passed to the current script through the http post method.

Therefore, you can pass the variables you want to pass to the next page through url or form post to the next page.

Criticize:

You think $ mes will get the result of this js execution. This shows that your basic skills are too weak and it is necessary to complete the basic knowledge.

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.