Hi,
I'm trying to build a billing system using a grid to select the items that are billable in a time range. I have the following php file that feeds the grid and handles the post as in the blog tutorials. When the Save button is clicked the grid posts to the php page correctly but the update does not happen and I get the following error in firebug:
a is undefined
http://localhost/...../kendo.all.min.js
Line 8
Here's the php code:
<?php
$link = mysql_pconnect("localhost", "user", "pass") or die("Unable To Connect To Database Server");
mysql_select_db("db-name") or die("Unable To Connect To DB");
// add the header line to specify that the content type is JSON
header("Content-type: application/json");
// determine the request type
$verb = $_SERVER["REQUEST_METHOD"];
// handle a GET
if ($verb == "GET") {
$arr = array();
$rs = mysql_query("SELECT
contracts_copy.contractID AS ID,
contracts_copy.artistID,
contracts_copy.contract_number AS Contract,
contracts_copy.play_date AS Date,
contracts_copy.billable AS Billable
FROM
contracts_copy
WHERE
contracts_copy.play_date >= '2012-01-01' AND
contracts_copy.offer_status = 'Confirmed'
");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo "{\"data\":" .json_encode($arr). "}";
}
// handle a POST
if ($verb == "POST") {
// get the parameters from the post. escape them to protect against sql injection.
$Billable = mysql_real_escape_string($_POST["Billable"]);
$Id = mysql_real_escape_string($_POST["ID"]);
$rs = mysql_query("UPDATE contracts_copy SET billable = '" .$Billable."' WHERE contractID = '" .$Id."'");
if ($rs) {
echo json_encode($rs);
}
else {
header("HTTP/1.1 500 Internal Server Error");
echo "Update failed for ID: " .$Id;
}
}
?>
When viewing the json directly in the browser it works fine. The post from the grid looks fine too:
The Billable field is the only editable one and is passed correctly. The response from json is also correct...true. But the table is not updated with the Billable value (true) and the grid doesn't show the update.
Here's my page code:
<div id="wrap" class="k-content">
<div id="example" class="k-content">
<div id="grid"></div>
<script>
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: "../data/billable.php",
update: {
url: "../data/billable.php",
type: "POST"
}
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
},
batch: true,
autoSync: true,
pageSize: 30,
schema: {
data: "data",
model: {
id: "ID",
fields: {
Contract: { editable: false },
Date: { editable: false},
Billable: {editable: true, type: "boolean" }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 400,
toolbar: ["save", "cancel"],
columns: [
{ field:"ID", title: "ID", width: "25px" },
{ field: "Contract", title:"Contract", width: "150px" },
{ field: "Date", title:"Date", width: "150px" },
{ field: "Billable", width: "100px" }
],
editable: true
});
});
</script>
</div>
</div>
I hope someone can help. It's probably something simple I'm overlooking. It seems odd that I'd get the true response from my php/json page if the update didn't happen?
Any help is appreciated.
Tony
I'm trying to build a billing system using a grid to select the items that are billable in a time range. I have the following php file that feeds the grid and handles the post as in the blog tutorials. When the Save button is clicked the grid posts to the php page correctly but the update does not happen and I get the following error in firebug:
a is undefined
http://localhost/...../kendo.all.min.js
Line 8
Here's the php code:
<?php
$link = mysql_pconnect("localhost", "user", "pass") or die("Unable To Connect To Database Server");
mysql_select_db("db-name") or die("Unable To Connect To DB");
// add the header line to specify that the content type is JSON
header("Content-type: application/json");
// determine the request type
$verb = $_SERVER["REQUEST_METHOD"];
// handle a GET
if ($verb == "GET") {
$arr = array();
$rs = mysql_query("SELECT
contracts_copy.contractID AS ID,
contracts_copy.artistID,
contracts_copy.contract_number AS Contract,
contracts_copy.play_date AS Date,
contracts_copy.billable AS Billable
FROM
contracts_copy
WHERE
contracts_copy.play_date >= '2012-01-01' AND
contracts_copy.offer_status = 'Confirmed'
");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo "{\"data\":" .json_encode($arr). "}";
}
// handle a POST
if ($verb == "POST") {
// get the parameters from the post. escape them to protect against sql injection.
$Billable = mysql_real_escape_string($_POST["Billable"]);
$Id = mysql_real_escape_string($_POST["ID"]);
$rs = mysql_query("UPDATE contracts_copy SET billable = '" .$Billable."' WHERE contractID = '" .$Id."'");
if ($rs) {
echo json_encode($rs);
}
else {
header("HTTP/1.1 500 Internal Server Error");
echo "Update failed for ID: " .$Id;
}
}
?>
When viewing the json directly in the browser it works fine. The post from the grid looks fine too:
models[0][Billable] | true |
models[0][Contract] | EK.03.29-30.2012.HollySprings.NC |
models[0][Date] | 2012-03-29 |
models[0][ID] | 2218 |
models[0][artistID] | 73 |
The Billable field is the only editable one and is passed correctly. The response from json is also correct...true. But the table is not updated with the Billable value (true) and the grid doesn't show the update.
Here's my page code:
<div id="wrap" class="k-content">
<div id="example" class="k-content">
<div id="grid"></div>
<script>
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: "../data/billable.php",
update: {
url: "../data/billable.php",
type: "POST"
}
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
},
batch: true,
autoSync: true,
pageSize: 30,
schema: {
data: "data",
model: {
id: "ID",
fields: {
Contract: { editable: false },
Date: { editable: false},
Billable: {editable: true, type: "boolean" }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 400,
toolbar: ["save", "cancel"],
columns: [
{ field:"ID", title: "ID", width: "25px" },
{ field: "Contract", title:"Contract", width: "150px" },
{ field: "Date", title:"Date", width: "150px" },
{ field: "Billable", width: "100px" }
],
editable: true
});
});
</script>
</div>
</div>
I hope someone can help. It's probably something simple I'm overlooking. It seems odd that I'd get the true response from my php/json page if the update didn't happen?
Any help is appreciated.
Tony