【问题标题】:jquery ajax call in onsubmit function is not workingonsubmit 函数中的 jquery ajax 调用不起作用
【发布时间】:2014-08-22 09:50:34
【问题描述】:

我有表单提交页面 add_sale.php 和一个 ajax 页面 ajx_check_sale.php.Ajax 调用在 onsubmit 函数中。但是 ajax 不工作。任何人都可以提供任何解决方案 plz..

我有表单提交页面 add_sale.php 和一个 ajax 页面 ajx_check_sale.php.Ajax 调用在 onsubmit 函数中。但是 ajax 不工作。任何人都可以提供任何解决方案 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;     
 }

【问题讨论】:

  • “这不是工作”不是一个好问题。请详细说明您在控制台和网络选项卡中遇到的错误
  • 你能说出原因吗 plzz..
  • 在您的代码中sale_type 值来自选择框或文本字段?
  • 请看我的代码,编辑,使用选择框
  • console---Uncaught TypeError: undefined is not a function add_sale.php:200 Uncaught TypeError: Cannot read property 'old_password' of undefined add_sale.php:373 无法加载资源:net::ERR_FILE_NOT_FOUND chrome-extension://ibnjmihbbanannlbobkbmnmckjnmdnom/lib/angular-route.min.js.map 加载资源失败:net::ERR_FILE_NOT_FOUND chrome-extension://ibnjmihbbanannlbobkbmnmckjnmdnom/lib/jquery.min.map 加载资源失败:net: :ERR_FILE_NOT_FOUND chrome-extension://ibnjmihbbanannlbobkbmnmckjnmdnom/lib/angular.min.js.map

标签: php jquery mysql ajax


【解决方案1】:

我不确定是否存在语法错误,但也许您可以在运行网站后检查它,然后右键单击该网站并选择检查元素,然后转到控制台。你可能会在那里找到一些东西。你也可以使用 console.log('message'); .它的功能类似于警报,但仅在控制台选项卡上显示。

【讨论】:

  • console---Uncaught TypeError: Cannot read property 'old_password' of undefined add_sale.php:376 无法加载资源:net::ERR_FILE_NOT_FOUND chrome-extension://ibnjmihbbanannlbobkbmnmckjnmdnom/lib/jquery.min .map 加载资源失败:net::ERR_FILE_NOT_FOUND chrome-extension://ibnjmihbbanannlbobkbmnmckjnmdnom/lib/angular.min.js.map 加载资源失败:net::ERR_FILE_NOT_FOUND chrome-extension://ibnjmihbbanannlbobkbmnmckjnmdnom/lib/angular-route .min.js.map
猜你喜欢
  • 1970-01-01
  • 2014-01-24
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 1970-01-01
  • 2012-07-14
  • 2014-03-14
  • 1970-01-01
相关资源
最近更新 更多