JS and PHP Pass parameters

Source: Internet
Author: User
Tags php books

Http://jingyan.baidu.com/article/0aa22375b722ba88cd0d6446.html

This problem is often encountered in web development, in fact, the solution is very simple, is a few lines of code , but a variety of js, PHP books are not , Baidu down also a mess, some can use, and some can't use. Small series encountered this problem when seriously study a morning , study a little experience, hope can help you !

Method/Step
  1. First case:

    two not on the same page (JS one page, PHP on another page)

    The first method:

    Pass a URL to the parameter . JS Pass the past, PHP received, or PHP passed, JS received.

    Here to show the JS Pass the past, PHP received the situation.

    I use jquery, easy to write. JS Dom operation is troublesome.

  2. JS passes through the URL, the most important thing is to change the URL.

    Code:$ (The ID of the form). attr ("Action", new URL address);

    This is the URL to change the action of the form to achieve the purpose of the argument.

    Of course, after the completion of the table will generally jump, the data to the jump after the receipt page, where the database operation.

    Stick to my code and take this as a sample to describe it in detail.

  3. Again the PHP receive process, this is very simple. The commands to use are:

    $SS =$_post["parameter name in URL"];

    Very simple, PHP will automatically identify the URL and parse out the parameter values. However, it is important to note that the method property of form form is post, otherwise PHP cannot be received by post.

    URL parameters, parameter format to write pairs , the figure has a sample.

    Send a receive picture.

  4. Here is a detailed explanation of the use and principle of PHP's post[] method.

    Post[""] <-----------the value in parentheses is the name of each element of the form to which you method is a post.

    For example

    <form method= ' Post ' >

    <input name= ' 123 '/>

    </form>

    Then your PHP will be written as it is received:

    $ss =$_post["123"];

    The name must be on, otherwise the Post method does not work.

  5. The second method:

    PHP passes parameters to JS.

    This is actually the same as above, just become PHP change url,js receive parameters .

    Used more when querying data . Just a bit very pit, that is, JS receive parameters like the need of their own string processing, I have not found a good way. Send me the JS function that I wrote to receive two parameters.

    The code is as follows:

  6. Code:

    function Ana ()//(function name: English abbreviation for analysis)

    {

    var url = $ (window.parent.document). Find ("#rl"). attr ("src");

    var pq=typeof (URL);

    if (PQ = = "undefined") {

    var c=date ();

    return C; }

    Else

    {

    var p=url.indexof ("?");

    if (p!=-1)

    {

    var i=url.indexof ("=");

    i=i+1;

    var j=url.indexof ("&");

    var c1,c2;

    C1= "";

    C2= "";

    for (Var k=i;k<j;k++)

    {C1 +=url[k];}

    var S=url;

    Url= "";

    for (k=j;k<s.length;k++)

    {URL +=s[k];}

    I=url.indexof ("=");

    i=i+1;

    J=url.length;

    for (Var k=i;k<j;k++)

    {C2 +=url[k];}

    var c=new Array (C1,C2);

    return C;

    }

    Else

    {

    var c=date ();

    return C; Returns an array.

    }

  7. Second case:

    PHP and JS on the same page, PHP to pass to the JS variable.

    The introduction said, this thing is very simple, is a few lines of code, is not easy to find.

    So nonsense not much to say, paste code:

    Code can see, on one line, do not write, write also useless, change the variable name time is enough for you to write this line of code.

  8. Look at the code effect! Prove that my method is effective and I'm not lying to you.

    Steps to read

JS and PHP Pass parameters

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.