By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

how to submit form using ajax

100+
P: 254
Hi

I am displaying a page (result.php) using ajax and in this page I have few links when clicked opens a div popup. in which a form, a text field and a submit button is there. when I click submit it should display message in this page which called using ajax(result.php). but actually it is not happening. I want user to be on the same page i.e. result.php
Jun 23 '09 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
Can you post your code?
Jun 23 '09 #2

100+
P: 254
@acoder
here is the code for the page which is displayed using ajax in this page div popup opens form and that form I want to submit and display the message in this page or some thing like so that user can know that it is submitted and stays on this page

Expand|Select|Wrap|Line Numbers
  1. <a href="#" id="prin">Print</a> | <a href="#" onclick="setVisible('layer1');return false" target="_self">Send as Email</a>| <a href="#" id="std">Save to Desktop</a>
  2.  
  3. <div id="layer1">
  4.   <span id="close"><a href="javascript:setVisible('layer1')" style="text-decoration: none"><strong>Hide</strong></a></span>
  5.   <p><form method="post" action="" name="emailSubmit"> <label> Email Address<input type="text" /></label>
  6.   <br /><input type="submit" value="Send" name="EmainSend" /><input type="hidden" value="" id="hiddenEmail" name="emailfile" /></form></p>
  7. </div>
  8.  
Jun 23 '09 #3

acoder
Expert Mod 15k+
P: 16,027
So you want to send two values: the email text box and the hidden field. A form submit is simply an Ajax POST request to the action page. Remember that for post you need to send the values using the send() method, not via the URL as you would with GET. I would suggest that you add an ID to the text field, so that you can easily access it.
Jun 23 '09 #4

100+
P: 254
@acoder
Expand|Select|Wrap|Line Numbers
  1. var url="result.php";
  2.     url=url+"?q="+str;
  3.     url=url+"&sid="+Math.random();
  4.     xmlHttp.onreadystatechange=stateChanged ;
  5.     xmlHttp.open("GET",url,true);
  6.     xmlHttp.send(null);
  7.  
this is for using get method so what i need to change in this code.
Jun 27 '09 #5

acoder
Expert Mod 15k+
P: 16,027
Here is a simple POST example.
Jun 29 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.