【发布时间】: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