2011-03-29 51 views
0

我想在jqgrid從服務器輸入數據到網格後運行一個函數。被調用的函數將csrf標記更新爲下一個jqgrid請求的全局變量。jqgrid OnComplete運行一個不起作用的功能

$("#customer_grid").jqGrid({ 
    mtype: 'POST', 
    url:'jqgrid/customer', 
    postData: { <?php echo $csrf_token_name; ?>: csrf_token }, 
    datatype: 'json', 
    colNames:['Account #', 'Firstname', 'Surname','Postcode','Address 1','Address 2', 'Address 3', 'City', 'County', 
       'Country', 'Email', 'Home Tel', 'Mobile Tel', 'Work Tel'], 
    colModel :[ 
     {name:'id', index:'id', width:80}, 
     {name:'firstname', index:'firstname', width:80}, 
     {name:'surname', index:'surname', width:80}, 
     {name:'postcode', index:'postcode', width:80}, 
     {name:'address_1', index:'address_1', width:80}, 
     {name:'address_2', index:'address_2', width:80}, 
     {name:'address_3', index:'address_3', width:80}, 
     {name:'city', index:'city', width:80}, 
     {name:'county', index:'county', width:80}, 
     {name:'country', index:'country', width:65}, 
     {name:'email', index:'email', width:80}, 
     {name:'home_tel', index:'home_tel', width:80}, 
     {name:'mobile_tel', index:'mobile_tel', width:80}, 
     {name:'work_tel', index:'work_tel', width:80}, 
    ], 
    emptyRecords: "No Accounts Found", 
    pager: '#customer_grid_pager', 
    rowNum:10, 
    rowList:[5,10,25,50,100], 
    rownumbers: true, 
    sortname: 'id', 
    sortorder: 'desc', 
    viewrecords: true, 
    gridview : true, 
    caption: 'Customer Search', 
    height: '220', 
    autowidth: true, 
    onComplete: function(data, response) { 
      get_csrf_token(); 
      alert(csrf_token); 
    }, 
    ondblClickRow: function(id, row, column){    
      //alert('Hello World '+ id + ' ' + row + ' ' + column); 
      customer_id = id; 
      //alert(customer_id); 
      crud_action = 'update'; 
      $('#new_customer').show(); 
      $('#customer_search').hide(); 
      customer_crud('read'); 
      show('#details'); 
    } 



    }); 

Firebug顯示沒有javascript錯誤,get_csrf_token()沒有被調用,有什麼想法?

感謝

+0

你可以發佈get_csrf_token()函數嗎? – glomad 2011-03-29 17:01:52

+0

@ithcy get_csrf_token()使用GET從服務器中檢索令牌 – JohnCook 2011-03-29 17:11:44

+0

我在問,因爲如果該函數中有語法錯誤,則可能無法評估您的jqGrid代碼。但我不認爲這是問題。看到我的答案。 – glomad 2011-03-29 17:43:05

回答

1

我沒有看到onComplete列爲jqGrid event。你確定你不是故意使用gridCompleteloadComplete

1

你應該使用這一個gridComplete: function(data, response) { get_csrf_token(); alert(csrf_token); },