Looking for an example to fit into a demo I am doing...

I'd like the user to be able to enter text and click search using POST method
Once the next page has loaded, display that variable using GET

Only in AJAX please. Thanks in advance for your help.

Why do you need AJAX for this?

Once the next page has loaded, display that variable using GET

AJAX is typically used to perform functions without a page load. If the page is going to load anyway, it would be much simpler just to use a server side script.

I'd like the user to be able to enter text and click search using POST method
Once the next page has loaded, display that variable using GET

I don't believe that javascript can directly access the POST array. The server has to read the post array and then output it to the page before javascript can access it. Javascript can access the GET array however, through the url.

Thanks for the reply buddylee17...

So you think the best method would be to use...

PAGE 1

<form action="results.php" method="get">
<input name="name" type="text" /> </font><input value="Search" type="submit" /></form>

PAGE 2

<?php echo $_GET["name"]; ?>

Sure, what I was mainly trying to say was that AJAX should only be used to enhance the users experience.

A page submit or refresh can sometimes be inconvenient and time consuming. With AJAX, the user can click the search button, continue looking at the page, and seconds later the results are there.

Just don't abuse AJAX, because most of the data transmitted in an AJAX request is overhead (headers-usually 300-500 bytes depending on the browser). So even though the data request is only 5 bytes, you still send 300 to 500 bytes of data. So one page refresh can be faster than multiple AJAX requests. Also, if the page has to be reloaded anyway, AJAX is unnecessary.

Great! Thank you so much for the explanation.

I am just starting to get into AJAX and I love alot of the examples I see online. As this is for a demo, loading time isn't a concern. It's when the site goes live I would prefer to have less load on the backend servers.

This article has been dead for over six months. Start a new discussion instead.