how Submit forms with POST method and connect mysql using AJAX?

Discussion in 'JavaScript' started by uniojnqoifazy, Aug 31, 2011.

  1. #1
    hi all,
    i want connect DB and get value from DB, then send the value to javascript function on the same page , it's looks like have to using ajax,
    please someone else can tell me how to do ???


    
    <script>
    function excuteApplet()
            {
                document.getElementById('myapplet').go();
                 return true;
            }
    </script>
    <?
         if($_POST["submit"]=="Test")
                    {      
                             require_once("DB_config.php");
                              require_once("DB_class.php");
                             $db = new DB;
                            $db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
                            $db->query("select ID,valueA, valueB from customer ;");
                          while($row = $db->fetch_array())
                             {
                                    $valueA= $row['valueA'];
                                    $valueB= $row['valueB'];
                                    $ID= $row['ID'];
                                     $sql = "update customer set paid=1 where ID = '".$ID."'";
                                    $result = $db->update($sql);
                                      $value= $valueA;
                                            if($total>30)
                                            {
                                                    $value= trim($valueA);
                                            }
                                           else
                                             {
                                                  $value= trim($valueB);
                                            }
                                  }  //end while
                   } //end if
            ?>
                       <applet id="myapplet" code="myapplet.class" name="myapplet" width="0" height="0" >
                                  <PARAM NAME=customer VALUE=<? echo $value?>>   //get the value from dB , when form data have been send.....but how to do ????
                        </applet>
    
                        <form action=""  name="form1"  method="post">  
                         <input  name="btn" type="submit" value="Test" id="Test"   >
                        </form>
    
     
    
    
    Code (markup):

     
    uniojnqoifazy, Aug 31, 2011 IP
  2. xiconet

    xiconet Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2



    you can use jquery instead of xml HTTP Request .It is easy and good.

    First of all include jquery file to your page and

    function form_post(url,div_id){
    $('#'+div_id).html("<table width=100% height=100%><tr><td style='height:324px;width=300px;' valign='middle' align='center'><img src='loading_div.gif'/></td></tr></table>");
    $.post(url, {
    email: $('#email').val()
    }, function(response){
    setTimeout("LoadContent('"+div_id+"', '"+escape(response)+"')", 500);
    });
    return false;
    }
    function LoadContent(div_id, response) {
    $('#'+div_id).html(unescape(response));
    }

    url="Path of the url where your data of form to be submitted"

    div id = "responce load"

    you can check in my website : <a href=" http://www.xiconet.com">http://www.xiconet.com</a>
     
    xiconet, Sep 1, 2011 IP