我正在将此 html 代码用于 Keno 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: " ", 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 条相同数据)和一条新记录。
这是一个明确的示例(使用 firebug 检查发布请求)
首先点击保存按钮 (false, (111) 111-1111, 4,Fax) // 在我输入这个电话后 (111) 111-1111
第二次点击保存按钮 (false, (111) 111-1111, 4,Fax) 除了 (false, (222) 222-2222, 3,Work) // 之后我添加了这个 (222) 222-2222
有什么帮助吗??