PDA

View Full Version : how to pass variables into AJAX request?


snake_eyes
04-28-2007, 09:16 AM
Hello, Dear Guys how to pass variables into AJAX request,

I have this div in the PHP page:
<div id="display_poll"></div>

and this is the AJAX_common.php code:
<table width="125" border="0" cellspacing="0" cellpadding="0">
<form method="post" action="ajax_common.php">
<tr>
<td class="cell3">question</td>
</tr>
<tr>
<td class="cell4"><input type="radio" name="option_id" value="1">option 1</td>
</tr> <tr>
<td class="cell4"><input type="radio" name="option_id" value="2">option 2</td>
</tr> <tr>
<td class="cell4"><input type="radio" name="option_id" value="3">option 3</td>
</tr> <tr>
<td class="cell4">
<input type="hidden" name="action" value="vote">
<input type="hidden" name="poll_ident" value="22">
<input type="submit" class="button" value="vote">
<br>
<span class='click_span' onclick="MakeRequest('ajax_common.php?action=results&amp;poll_ident=22', 'display_poll')">results</span>
</td>
</tr>
</form>
</table>

when I select an option then submit the page it will reload again, is there a way to switch automatic the div and get the poll result instead of poll main form

regards heaps

chris_angell
04-30-2007, 11:28 AM
Hi there what you need to do is on your submit button ,,, run a function and from the function call a javascript function that will talk to your to your php page and then return the content that will go into your div

you use the GetXmlHttpObject() to talk to your php page

so in your return javascript ajax will be:

document.getElementById('display_poll').innerHTML=xmlHttp.responseText;

and this will replace the inner content... you dont need to post..

snake_eyes
04-30-2007, 11:46 AM
Hello chris_angell,

I already have <div id="display_poll"></div> and the table of AJAX_common.php has loaded and published to display_poll like document.getElementById('display_poll').innerHTML=xmlHttp.responseText;

for sure when you vote the original form should be change to poll result and replace the original form.

if you have a small example much better,

Regards

mrsylves
10-19-2009, 09:29 PM
snake_eyes
The <div id="display_poll"></div> worked perfectly for my uses. Thanks a ton.:thumbsup:

- Los Angeles DUI Lawyer (http://www.dui1guy.com/why-hire-a-lawyer-for-dui)

snake_eyes
10-20-2009, 06:23 AM
hehehe

it is too late my dear, I finished this project since 2 years and I forget its code
:D:D:D:D:D