jquery ajax call in onsubmit function is not working

Posted by shilna mk on Stack Overflow See other posts from Stack Overflow or by shilna mk
Published on 2014-08-22T09:50:34Z Indexed on 2014/08/22 10:20 UTC
Read the original article Hit count: 372

Filed under:
|
|
|

I have form submission page add_sale.php and an ajax page ajx_check_sale.php.Ajax call is inthe onsubmit function.But ajax is not worikng.Anybody give any solution plz..

I have form submission page add_sale.php and an ajax page ajx_check_sale.php.Ajax call is inthe onsubmit function.But ajax is not worikng.Anybody give any solution plz..

add_sale.php

function sale_credit(id)

{ var cust_name=$('#cust_name').val();

$.ajax({
    type: "POST",
    url: 'ajx_typ1.php',
    data:'id='+id,
    success: function(msg)
     { 
      $("#sale_type1").html(msg);

     }

});

$.ajax({
    type: "POST",
    url: 'ajx_typ3.php',
    data:'id='+id,
    success: function(msg)
     { 
      $("#sale_type3").html(msg);

     }

});

$.ajax({ type: "POST", url: 'ajx_typ2.php', data:'id='+id, success: function(msg) { $("#sale_type2").html(msg);

     }
     });


}


 function validate_form()
     {
     var cust_name= $('#cust_name').val();
     var total= $('#total').val();
      var sale_type= $('#sale_type').val();

     if(sale_type=='return')
     {
        $.ajax({
        type: "POST",
        url: 'ajx_check_sale.php',
        data:'cust_name='+cust_name + '&total=' + total,
        success: function(msg)
         { 

         alert(msg);
          /*if(msg==0)
           {

             alert("Return is greater then sale"); 
             return false;  
           } */
         }
      });
     }
    }
    <form action="" method="post" name="adFrm" onSubmit="return validate_form()">
      <select name="sale_type" style="width:130px;" 
         id="sale_type"   onchange="sale_credit(this.value)"  >

                <option value="">Select</option>
                <option   value="credit">Credit</option>
                <option  value="payment">Payment</option>
                <option  value="return">Return</option>

              </select>
    </form>

ajx_check_sale.php

 require_once("codelibrary/inc/variables.php");
 require_once("codelibrary/inc/functions.php");
 echo $cust_name=$_POST['cust_name'];
 echo $return=$_POST['total'];

 $cus="select sum(total) as total_sum from customer where id='$cust_id'";
 $cus2=mysql_query($cus);
 $fet=mysql_fetch_array($cus2);
 $total=$fet['total_sum'];

if($return>$total)
 {
     $status=0; 
     echo $status;  
 }
else
 {
      $status=1;    
      echo $status;     
 }

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery