onsubmit函数中的jquery ajax调用无法正常工作

时间:2014-08-22 09:50:35

标签: php jquery mysql ajax

我有表单提交页面add_sale.php和ajax页面ajx_check_sale.php.Ajax调用是在onsubmit函数中。但是ajax不是worikng.Anybody给出任何解决方案plz ..

我有表单提交页面add_sale.php和ajax页面ajx_check_sale.php.Ajax调用是在onsubmit函数中。但是ajax不是worikng.Anybody给出任何解决方案plz ..

add_sale.php

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>

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);

    }
  });


}

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;     
 }

1 个答案:

答案 0 :(得分:0)

我不确定是否存在语法错误,但您可以在运行网站后检查它,然后右键单击网站并选择Inspect Elements,然后转到控制台。你可能会找到一些东西。您也可以使用console.log(&#39; message&#39;); 。它将像警报一样运行,但仅在控制台选项卡上显示。