Conor Conor - 1 year ago 87
jQuery Question

How to get data sent from 1 page to another?

I have two page -
1. Index.html

2. Main.html

I want to sent a data from index to main. Which i can do like this:

<form action="Main.html" method="POST">
<input type="text" name="q">

I want to display the data sent from Index.html on Main.html

I know two methods of doing it -

1. using
in the form tag and get the data from the src(link).

2. Using side languages like php.

I dont want to use the first method to do this thing.

Please someone give me the codes of php for doing this.

It would be more help if you can tell any other way of doing this

Answer Source
  1. Change your Main.html to Main.php
  2. To get data in the Main.php with post method is just: $_POST['q'].

If you want to display your input text, just echo it: echo $_POST['q'].

Or you can save it into a variable too: $var = $_POST['q'].

Or if you don't want to use PHP, you can save input's value into a cookie and get that cookie's value in the Main.html with just JavaScript.

// function to get cookie || Parameter is your required cookie's name
function getcookie(cookiename)
    var name = cookiename+"=";
    var cookiearray = document.cookie.split(';');
    for(var i=0; i<cookiearray.length; i++)
        var c = cookiearray[i].trim();
        if(c.indexOf(name) === 0)
            return c.substring(name.length, c.length);
    return "";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download