2013-02-21 53 views
0

我正在使用custom_func来验证编辑中的字段并为表单编辑添加。这个custom_func正在调用服务器的ajax来验证帐号。问题是该列没有被发送到PHP。将列传递给外部ajax调用

jQuery函数:

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

PHP函数:

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

我尝试使用数据:{cntrct_id:“cntrct_id '}在该行的editoptions中手动将该列的值发送到服务器,但无济于事。我还能尝试什么?

回答

1

您未发布cntrct_id字段,您只能发布chkAcct

你需要将它添加到数据对象张贴合同区:

data: { 
    action: 'chkAcct', 
    cntrct_id: $('#cntrct_id').val() 
} 

更换$('#cntrct_id')用正确的参照数据。

+0

mcryan,您的解决方案已解决我的问题。我必须添加该列必须被引用为$('#cntrct_id')。val(),因为$('#cntrct_id')打破了网格。只要SO允许,我会尽快接受答案。 – user 2013-02-21 15:17:00

+0

太好了。我已将'.val()'添加到我的答案中。 – mcryan 2013-02-21 15:22:59