how to submit form using ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshrasm
    Contributor
    • Nov 2007
    • 254

    how to submit form using ajax

    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you post your code?

    Comment

    • mukeshrasm
      Contributor
      • Nov 2007
      • 254

      #3
      Originally posted by acoder
      Can you post your code?
      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

      [code=html]
      <a href="#" id="prin">Print </a> | <a href="#" onclick="setVis ible('layer1'); return false" target="_self"> Send as Email</a>| <a href="#" id="std">Save to Desktop</a>

      <div id="layer1">
      <span id="close"><a href="javascrip t:setVisible('l ayer1')" style="text-decoration: none"><strong>H ide</strong></a></span>
      <p><form method="post" action="" name="emailSubm it"> <label> Email Address<input type="text" /></label>
      <br /><input type="submit" value="Send" name="EmainSend " /><input type="hidden" value="" id="hiddenEmail " name="emailfile " /></form></p>
      </div>
      [/code]
      Last edited by acoder; Jun 23 '09, 11:49 AM. Reason: Fixed code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        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.

        Comment

        • mukeshrasm
          Contributor
          • Nov 2007
          • 254

          #5
          Originally posted by acoder
          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.
          [Code=JavaScript]
          var url="result.php ";
          url=url+"?q="+s tr;
          url=url+"&sid=" +Math.random();
          xmlHttp.onready statechange=sta teChanged ;
          xmlHttp.open("G ET",url,true) ;
          xmlHttp.send(nu ll);
          [/Code]

          this is for using get method so what i need to change in this code.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Here is a simple POST example.

            Comment

            Working...