JS to write PHP code

Source: Internet
Author: User
Tags vars
Common.jsfunction gourl (lang) {...//   $_session[' language ']=lang   this code in JS how to write? ...}


Reply to discussion (solution)

The interaction between JS and PHP is best done with Ajax

PHP is generally embedded in the JS, where is the JS write php ah, to the server support.

function Gourl (lang) {
...

...
}

JS to be associated with PHP, the general is to use the AJAX request, if it is in the JS load to get (take) session value, you can write in the JS code block If you want to load the page when the session is set, this with JS is OK, you can directly

main.inc.php
 index.php
 Display (' index.html ');? >index.html[code=php]            
 
  
                 <title></title>            
  • Propagation
  • Jane
  • New
  • Complex, complex, complex, complexCommon.jsfunction gourl (lang) {var url = document.location.href; var query = window.location.search.substring (1); var urls = url.replace (Window.location.hash, "). Split ("? "); var VARs = Query.split ("&"); var query = ""; for (Var i=0;i
    Click index.html "Fan" switch language (complex)
    I change $_session[' language ' at the same time I call Gourl ()
    So I would like to add PHP code in JS, if the following will be an error, to find a solution
    function Gourl (lang) {
    ...

    ...
    }

    1, the session variable is stored on the server side, the client cannot actively modify
    2. You have location.href in gourl () = urls[0]+ "?" +query+window.location.hash; Jump
    So you should do the session variable setting in the program file pointed to by Urls[0].

    1, the session variable is stored on the server side, the client cannot actively modify
    2. You have location.href in gourl () = urls[0]+ "?" +query+window.location.hash; Jump
    So you should do the session variable setting in the program file pointed to by Urls[0].



    After the jump is also to index.php->index.html execution of the Gourl () when the original link is added? Lang=xx to change the language

    function Gourl (lang) {
    var url = document.location.href;
    var query = window.location.search.substring (1);
    var urls = url.replace (Window.location.hash, "). Split ("? ");
    var VARs = Query.split ("&");
    var query = "";
    for (Var i=0;i
    var pair = Vars[i].split ("=");
    if (pair[0]! = "Lang" && pair[0]! = "") {
    query = query + pair[0] + "=" + pair[1] + "&";
    }
    }
    query = query + "lang=" + lang;
    Location.href = urls[0]+ "?" +query+window.location.hash;
    }
    I would like to create a gourl.php to replace the above in PHP how to implement this JS function

    After changing the language, the page needs to be refreshed, and your original writing does not need to change
    Your gourl.php is always going to output the content of the page like index.php. Does it seem cumbersome?

  • 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.