2013-06-19 25 views
0

我使用這個HTML代碼基諾UI電網添加記錄功能在劍道UI電網被稱爲多次

function loadPhoneGrid(salesRepsId){ 
         $("#phone-grid").kendoGrid({ 
         dataSource: { 
          transport: { 
           read: { 
            url: "operations/get_phones_sales_reps.php?salesRepsId="+salesRepsId, 
            type: "GET" 
           }, 
           update: { 
            url: "operations/edit_phone_number.php?salesRepsId="+salesRepsId, 
            type: "POST" 
           }, 
           destroy: { 
            url: "operations/delete_phone.php", 
            type: "POST" 
           }, 
           create: { 
            url: "operations/add_phone.php?salesRepsId="+salesRepsId, 
            type: "POST", 
           }, 
          }, 
          schema: { 
           data:"data", 
           total: "data.length", //total amount of records 
           model: { 
            id: "PhoneId", 
            fields: { 
             PhoneType: { defaultValue: { PhoneTypeId: 1, PhoneTypeName: "Work"} }, 
             PhoneNumber: { type: "string" }, 
             IsMainPhone: {type: "boolean", editalbe:true}, 
            } 
           } 

          }, 
          pageSize: 5, 
         }, 
         height: 250, 
         filterable: true, 
         sortable: true, 
         pageable: true, 
         reorderable: false, 
         groupable: false, 
         batch: true, 
         toolbar: ["create", "save", "cancel"], 
         editable: true, 
         columns: [ 
          { 
           field:"PhoneType", 
           title:"Type", 
           editor: PhoneTypeDropDownEditor, 
           template: "#=PhoneType.PhoneTypeName#" 
          }, 
          { 
           field: "PhoneNumber", 
           title:"Phone Number", 

          }, 
          { 
           field: "IsMainPhone", 
           title:"Is Main", 
           width: 65, 
           template: function (e){ 
            if(e.IsMainPhone== true){ 
             return '<img align="center" src ="images/check-icon.png" />'; 
            }else{ 
             return ''; 
            } 
           } 
           // hidden: true 

          }, 
          { command: "destroy", title: "&nbsp;", width: 90 }, 

          ], 


        }); 

       } 

在服務器端的代碼是(add_phone.php)

<?php 
require_once("../lib/Phone.php"); 

$phone = array(); 
foreach($_POST as $name => $value){ 
    $phone[$name] = $value; 
} 
Phone::AddPhoneNumber($_GET["salesRepsId"], $phone); 
?> 

我第一次添加了一個新記錄。 add_phone.php正在調用一次,一切正常。當我嘗試添加新記錄時,第二次(不刷新頁面),add_phone.php被調用兩次。其中之一包含之前已添加到數據庫的第一條記錄,第二條記錄是新數據。

在結果我有3條記錄(2個相同的數據的第一次插入)和一個新的。

這樣的一個例子,以明確(檢查與螢火蟲POST請求)

首先點擊保存按鈕(假的,(111)111-1111,4,傳真)//後,我進入這個電話( 111)111-1111

除了(false,(222)222-2222,3,Work)之外,//在添加之後,第二次點擊保存按鈕(false,(111)111-1111,4,Fax)這(222)222-2222

任何幫助?

回答

0

可能是您的ajax請求引發錯誤。您可以通過訂閱數據源的錯誤事件來查看它。

如果發生錯誤,數據在您的數據源中不同步。在你的情況下,我認爲你的數據項保持在「髒模式」,所以數據源嘗試插入它們進行每次同步...