Php 将列传递给外部ajax调用
我正在使用自定义函数验证编辑和添加表单编辑中的字段。此自定义函数正在对服务器进行ajax调用,以验证帐号。问题是该列没有发布到php JQUERY函数:Php 将列传递给外部ajax调用,php,jqgrid,Php,Jqgrid,我正在使用自定义函数验证编辑和添加表单编辑中的字段。此自定义函数正在对服务器进行ajax调用,以验证帐号。问题是该列没有发布到php JQUERY函数: function chkAcct(value,colname){ // var result = null; $.ajax({ async: false, url: 'functions.php', type: 'POST', data: {action: 'chk
function chkAcct(value,colname){
// var result = null;
$.ajax({
async: false,
url: 'functions.php',
type: 'POST',
data: {action: 'chkAcct'},
// dataType: 'xml',
// contentType: 'application/xml; charset=utf-8',
success: function(response){
if(response){
result = [true,""];
}
else{
result = [false,"This account already exists"];
}
alert(response);
},
});
return result;
}
function chkAcct($conn){
$sql = "SELECT dist_id FROM batch WHERE open_flg = '1'";
$query = pg_query($conn,$sql);
$row = pg_fetch_row($query);
$dist = distConversion($row[0]);
$cntrct_id = $dist.$_POST['cntrct_id'];
$sql = "SELECT COUNT(*) FROM addru ad, cntrt ct WHERE ct.cntrct_id = '$cntrct_id' AND ad.cntrct_seq = ct.cntrct_seq AND ad.active_flg = '1'";
$query = pg_query($conn,$sql);
$row = pg_fetch_row($query);
$count1 = $row[0];
$sql = "SELECT COUNT(*) FROM nmaddr nm WHERE nm.cntrct_id = '$cntrct_id'";
$query = pg_query($conn,$sql);
$row = pg_fetch_row($query);
$count2 = $row[0];
$total = $count1+$count2;
if($total === 0){
$myfile = "text.txt";
$fh = fopen($myfile,'a');
fwrite($fh,$total);
fclose($fh);
echo $cntrct_id;
}
}
PHP函数:
function chkAcct(value,colname){
// var result = null;
$.ajax({
async: false,
url: 'functions.php',
type: 'POST',
data: {action: 'chkAcct'},
// dataType: 'xml',
// contentType: 'application/xml; charset=utf-8',
success: function(response){
if(response){
result = [true,""];
}
else{
result = [false,"This account already exists"];
}
alert(response);
},
});
return result;
}
function chkAcct($conn){
$sql = "SELECT dist_id FROM batch WHERE open_flg = '1'";
$query = pg_query($conn,$sql);
$row = pg_fetch_row($query);
$dist = distConversion($row[0]);
$cntrct_id = $dist.$_POST['cntrct_id'];
$sql = "SELECT COUNT(*) FROM addru ad, cntrt ct WHERE ct.cntrct_id = '$cntrct_id' AND ad.cntrct_seq = ct.cntrct_seq AND ad.active_flg = '1'";
$query = pg_query($conn,$sql);
$row = pg_fetch_row($query);
$count1 = $row[0];
$sql = "SELECT COUNT(*) FROM nmaddr nm WHERE nm.cntrct_id = '$cntrct_id'";
$query = pg_query($conn,$sql);
$row = pg_fetch_row($query);
$count2 = $row[0];
$total = $count1+$count2;
if($total === 0){
$myfile = "text.txt";
$fh = fopen($myfile,'a');
fwrite($fh,$total);
fclose($fh);
echo $cntrct_id;
}
}
最后,讨论中的这一行:
{ name:'cntrct_id',
editoptions:{ maxlength:8 },
editrules:{
custom:true,
custom_func: chkAcct,
}
},
我尝试在行的editoptions中使用数据:{cntrct_id:'cntrct_id'}手动将列的值发送到服务器,但没有效果。我还能试什么 您没有发布
cntrct\u id
字段,您只是发布chkAcct
您需要通过将合同字段添加到数据对象来过账:
data: {
action: 'chkAcct',
cntrct_id: $('#cntrct_id').val()
}
用正确的数据引用替换
$('cntrct_id')
。mcryan,您的解决方案解决了我的问题。我必须补充一点,该列必须被引用为$('cntrct_id').val(),因为$('cntrct_id')破坏了网格。我会尽快接受你的回答。太好了。我在答案中添加了.val()
。