php with kendo grip, easy demo of create destory update and read, but create and update have the same js problem.
It return status : 200,so it works. And it has already persisted the database record, but js error:Uncaught SyntaxError: Unexpected number , so the popup update window can't close.
BTW, I didn't return in the background logic php. I have try return json ,but still same problem.
source code:
<div id="user_grid"></div>
<script>
$(document).ready(function() {
getUserGrid("doAdminAction.php?act=");
});
function getUserGrid(crudServiceBaseUrl) {
var dataSource = new kendo.data.DataSource({
transport : {
read : {
url : crudServiceBaseUrl + "getAllUsers",
dataType : "json"
},
update : {
url : crudServiceBaseUrl + "updateUser",
contentType : "application/json",
type : "post"
},
create : {
url : crudServiceBaseUrl + "insertUser",
contentType : "application/json",
type : "post"
},
destroy : {
url : crudServiceBaseUrl + "delUser",
contentType : "application/json",
type : "post"
},
parameterMap : function(options, operation) {
if (operation !== "read" && options.models) {
return kendo.stringify(options.models);
}
}
},
batch : true,
pageSize : 50,
schema : {
model : {
id : "id",
fields : {
id : {
editable : false,
type : "number",
nullable : false
},
GUID : {
editable : false,
},
username : {
editable : true,
validation : {
required : true
}
}
}
}
}
});
$("#user_grid").kendoGrid({
dataSource : dataSource,
navigatable : true,
pageable : {
refresh : true,
pageSizes : true,
buttonCount : 2
},
sortable : true,
filterable : true,
groupable : true,
columnMenu : true,
editable : "popup",
resizable : true,
height : 720,
toolbar : [ {
name : "create",
text : "添加新用户"
} ],
columns : [ {
field : "id",
type : "number",
hidden : true,
},{
field : "username",
title : "用户名",
width : 50
},{
command : [ {
name : "edit",
text : "编辑"
}, {
name : "destroy",
text : "删除"
} ],
title : "操作栏",
width : 100
} ]
});
};
</script>
</div>
</div>
It return status : 200,so it works. And it has already persisted the database record, but js error:Uncaught SyntaxError: Unexpected number , so the popup update window can't close.
BTW, I didn't return in the background logic php. I have try return json ,but still same problem.
source code:
<div id="user_grid"></div>
<script>
$(document).ready(function() {
getUserGrid("doAdminAction.php?act=");
});
function getUserGrid(crudServiceBaseUrl) {
var dataSource = new kendo.data.DataSource({
transport : {
read : {
url : crudServiceBaseUrl + "getAllUsers",
dataType : "json"
},
update : {
url : crudServiceBaseUrl + "updateUser",
contentType : "application/json",
type : "post"
},
create : {
url : crudServiceBaseUrl + "insertUser",
contentType : "application/json",
type : "post"
},
destroy : {
url : crudServiceBaseUrl + "delUser",
contentType : "application/json",
type : "post"
},
parameterMap : function(options, operation) {
if (operation !== "read" && options.models) {
return kendo.stringify(options.models);
}
}
},
batch : true,
pageSize : 50,
schema : {
model : {
id : "id",
fields : {
id : {
editable : false,
type : "number",
nullable : false
},
GUID : {
editable : false,
},
username : {
editable : true,
validation : {
required : true
}
}
}
}
}
});
$("#user_grid").kendoGrid({
dataSource : dataSource,
navigatable : true,
pageable : {
refresh : true,
pageSizes : true,
buttonCount : 2
},
sortable : true,
filterable : true,
groupable : true,
columnMenu : true,
editable : "popup",
resizable : true,
height : 720,
toolbar : [ {
name : "create",
text : "添加新用户"
} ],
columns : [ {
field : "id",
type : "number",
hidden : true,
},{
field : "username",
title : "用户名",
width : 50
},{
command : [ {
name : "edit",
text : "编辑"
}, {
name : "destroy",
text : "删除"
} ],
title : "操作栏",
width : 100
} ]
});
};
</script>
</div>
</div>
10 Answers, 1 is accepted
0
Hi Alan,
From the provided information it seems that the reason for current behavior is that the sever response is not correctly formatted - it should be valid JSON array with only one item (the updated one). Could you please try to update the server code and let us know of the result?
Regards,
Vladimir Iliev
Telerik
From the provided information it seems that the reason for current behavior is that the sever response is not correctly formatted - it should be valid JSON array with only one item (the updated one). Could you please try to update the server code and let us know of the result?
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Alan
Top achievements
Rank 1
answered on 24 Sep 2014, 06:58 AM
Hi Iliev,
Thx for your answer.I will try tonight and paste my response string for you.
But I check the demo of php version, it also returns an empty array.
I just confused why it didn't works in my project.
Thx for your answer.I will try tonight and paste my response string for you.
But I check the demo of php version, it also returns an empty array.
I just confused why it didn't works in my project.
0
Hello Alan,
I will leave the thread open to let you test the changes and provide more information if needed.
Regards,
Vladimir Iliev
Telerik
I will leave the thread open to let you test the changes and provide more information if needed.
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Alan
Top achievements
Rank 1
answered on 04 Oct 2014, 03:36 PM
Hi Iliev,
Thanks for your patience, I'm busy these time, so I still no idea of this problem. Below is some detail of this problem, plz check and give me some advice, thx
1、js Error
![]()
2、request
![]()
3、response
{"id":13,"url":"1231","description":"test","type":"2","status":true,"href":"123123"}
Thanks for your patience, I'm busy these time, so I still no idea of this problem. Below is some detail of this problem, plz check and give me some advice, thx
1、js Error
2、request
3、response
{"id":13,"url":"1231","description":"test","type":"2","status":true,"href":"123123"}
0

Alan
Top achievements
Rank 1
answered on 04 Oct 2014, 03:43 PM
Seems I can't post picture....
js error:
Uncaught SyntaxError: Unexpected number kendo.all.min.js:9 gt.setter kendo.all.min.js:9 ct.extend._set kendo.all.min.js:11 Wt.extend.accept kendo.all.min.js:11 ct.extend._accept kendo.all.min.js:11 (anonymous function) kendo.all.min.js:11 (anonymous function) jquery-1.9.1.js:7478 c jquery-1.9.1.js:7341 p.fireWith jquery-1.9.1.js:7403 i.(anonymous function) jquery-1.9.1.js:7529 r.transport.(anonymous function).call.J.success kendo.all.min.js:11 c jquery-1.9.1.js:7341 p.fireWith jquery-1.9.1.js:7403 k jquery-1.9.1.js:9597 r jquery-1.9.1.js:9597
request:
[{"status":false,"href":"123","type":"1","description":"13213","url":"123","id":14}]
js error:
Uncaught SyntaxError: Unexpected number kendo.all.min.js:9 gt.setter kendo.all.min.js:9 ct.extend._set kendo.all.min.js:11 Wt.extend.accept kendo.all.min.js:11 ct.extend._accept kendo.all.min.js:11 (anonymous function) kendo.all.min.js:11 (anonymous function) jquery-1.9.1.js:7478 c jquery-1.9.1.js:7341 p.fireWith jquery-1.9.1.js:7403 i.(anonymous function) jquery-1.9.1.js:7529 r.transport.(anonymous function).call.J.success kendo.all.min.js:11 c jquery-1.9.1.js:7341 p.fireWith jquery-1.9.1.js:7403 k jquery-1.9.1.js:9597 r jquery-1.9.1.js:9597
request:
[{"status":false,"href":"123","type":"1","description":"13213","url":"123","id":14}]
0

Alan
Top achievements
Rank 1
answered on 04 Oct 2014, 03:46 PM
PHP Source Code (Page) :
<div id="index_grid"></div>
<script>
$(document).ready(function() {
getIndexGrid("doAdminAction.php?act=");
});
function getIndexGrid(crudServiceBaseUrl) {
var dataSource = new kendo.data.DataSource({
transport : {
read : {
url : crudServiceBaseUrl + "getIndexItems",
dataType : "json"
},
update : {
url : crudServiceBaseUrl + "updateIndexItem",
contentType : "application/json",
type : "post"
},
create : {
url : crudServiceBaseUrl + "insertIndexItem",
contentType : "application/json",
type : "post"
},
destroy : {
url : crudServiceBaseUrl + "delIndexItem",
contentType : "application/json",
type : "post"
},
parameterMap : function(options, operation, e) {
if (operation !== "read" && options.models) {
return kendo.stringify(options.models);
}
}
}
},
batch : true,
pageSize : 20,
schema : {
model : {
id : "id",
fields : {
id : {
editable : false,
type : "number",
nullable : false
},
url : {
editable : true
},
description : {
editable : true
},
type : {
defaultValue: 1
},
status : {
type : "boolean",
editable : true
}
}
}
}
});
var grid = $("#index_grid").kendoGrid({
dataSource : dataSource,
navigatable : true,
pageable : {
refresh : true,
pageSizes : true,
buttonCount : 2
},
sortable : true,
filterable : true,
groupable : true,
columnMenu : true,
editable : "inline",
resizable : true,
height : 720,
toolbar : [ {
name : "create",
text : "添加首页项"
} ],
columns : [ {
field : "id",
type : "number",
hidden : true,
},{
field : "type",
title : "类别",
editor: categoryDropDownEditor,
template: "#=type==2? '动态幻灯片':'静态推荐品'#",
width : 50
}, {
field : "description",
title : "标题",
width : 70
}, {
field : "url",
title : "图片名",
width : 70
}, {
field : "href",
title : "超链接",
width : 70
}, {
field : "status",
type : "boolean",
title : "激活",
width : 40
}, {
command : [ {
name : "edit",
text : "编辑"
}, {
name : "destroy",
text : "删除"
} ],
title : "操作栏",
width : 100
} ]
});
};
function categoryDropDownEditor(container, options) {
var data = [
{ text: "静态推荐品", value: "1" },
{ text: "动态幻灯片", value: "2" }
];
$('<input data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataTextField: "text",
dataValueField: "value",
dataSource: data
});
};
</script>
<div id="index_grid"></div>
<script>
$(document).ready(function() {
getIndexGrid("doAdminAction.php?act=");
});
function getIndexGrid(crudServiceBaseUrl) {
var dataSource = new kendo.data.DataSource({
transport : {
read : {
url : crudServiceBaseUrl + "getIndexItems",
dataType : "json"
},
update : {
url : crudServiceBaseUrl + "updateIndexItem",
contentType : "application/json",
type : "post"
},
create : {
url : crudServiceBaseUrl + "insertIndexItem",
contentType : "application/json",
type : "post"
},
destroy : {
url : crudServiceBaseUrl + "delIndexItem",
contentType : "application/json",
type : "post"
},
parameterMap : function(options, operation, e) {
if (operation !== "read" && options.models) {
return kendo.stringify(options.models);
}
}
}
},
batch : true,
pageSize : 20,
schema : {
model : {
id : "id",
fields : {
id : {
editable : false,
type : "number",
nullable : false
},
url : {
editable : true
},
description : {
editable : true
},
type : {
defaultValue: 1
},
status : {
type : "boolean",
editable : true
}
}
}
}
});
var grid = $("#index_grid").kendoGrid({
dataSource : dataSource,
navigatable : true,
pageable : {
refresh : true,
pageSizes : true,
buttonCount : 2
},
sortable : true,
filterable : true,
groupable : true,
columnMenu : true,
editable : "inline",
resizable : true,
height : 720,
toolbar : [ {
name : "create",
text : "添加首页项"
} ],
columns : [ {
field : "id",
type : "number",
hidden : true,
},{
field : "type",
title : "类别",
editor: categoryDropDownEditor,
template: "#=type==2? '动态幻灯片':'静态推荐品'#",
width : 50
}, {
field : "description",
title : "标题",
width : 70
}, {
field : "url",
title : "图片名",
width : 70
}, {
field : "href",
title : "超链接",
width : 70
}, {
field : "status",
type : "boolean",
title : "激活",
width : 40
}, {
command : [ {
name : "edit",
text : "编辑"
}, {
name : "destroy",
text : "删除"
} ],
title : "操作栏",
width : 100
} ]
});
};
function categoryDropDownEditor(container, options) {
var data = [
{ text: "静态推荐品", value: "1" },
{ text: "动态幻灯片", value: "2" }
];
$('<input data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataTextField: "text",
dataValueField: "value",
dataSource: data
});
};
</script>
0

Alan
Top achievements
Rank 1
answered on 04 Oct 2014, 03:53 PM
PHP source code( background logic):
$insertArr= json_decode(substr(file_get_contents('php://input'),1,-1));
if (!is_array($insertArr)) {
$insertArr= array($insertArr);
}
if(($insertArr['id']=insert("db_test",$insertArr))!=0){
echo json_encode($insertArr);
}else{
echo json_encode(array());
}
Database insert Function:
function insert($table,$array){
$keys=join(",",array_keys($array));
$vals="'".join("','",array_values($array))."'";
$sql="insert into {$table}($keys) values({$vals})";
mysql_query($sql);
return mysql_insert_id();
}
$insertArr= json_decode(substr(file_get_contents('php://input'),1,-1));
if (!is_array($insertArr)) {
$insertArr= array($insertArr);
}
if(($insertArr['id']=insert("db_test",$insertArr))!=0){
echo json_encode($insertArr);
}else{
echo json_encode(array());
}
Database insert Function:
function insert($table,$array){
$keys=join(",",array_keys($array));
$vals="'".join("','",array_values($array))."'";
$sql="insert into {$table}($keys) values({$vals})";
mysql_query($sql);
return mysql_insert_id();
}
0
Hello Alan,
I tried to reproduce the issue on our side with the provided code but to no avail - the record is updated / created without JavaScript errors. Could you please create small runable example where the issue is reproduced and send it back to us (the example can be single page, and the PHP controller can return static data on read/create)? This would help us pinpoint the exact reason for this behavior.
Regards,
Vladimir Iliev
Telerik
I tried to reproduce the issue on our side with the provided code but to no avail - the record is updated / created without JavaScript errors. Could you please create small runable example where the issue is reproduced and send it back to us (the example can be single page, and the PHP controller can return static data on read/create)? This would help us pinpoint the exact reason for this behavior.
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Alan
Top achievements
Rank 1
answered on 08 Oct 2014, 02:07 PM
This is a demo. Plz check.
1、sql file is also attached in the test.zip.
2、The environment is PHP+Win7+MySql, I just use Xampp to test it.
3、you may need to change the database definition in configs/configs.php
Looking forward to your good news.
Thanks and Best Regards,
Alan
1、sql file is also attached in the test.zip.
2、The environment is PHP+Win7+MySql, I just use Xampp to test it.
3、you may need to change the database definition in configs/configs.php
Looking forward to your good news.
Thanks and Best Regards,
Alan
0
Hi Alan,
Thank you for the provided project - it was easily run on our side.
After checking it I notice that the response from the server during create/update actions is not parsed from JSON - the reason for this behavior is that the "dataType" option is not set for this operations:
After setting the above option, the project start working as expected on our side.
Regards,
Vladimir Iliev
Telerik
Thank you for the provided project - it was easily run on our side.
After checking it I notice that the response from the server during create/update actions is not parsed from JSON - the reason for this behavior is that the "dataType" option is not set for this operations:
update : {
url : crudServiceBaseUrl +
"updateIndexItem"
,
contentType :
"application/json"
,
dataType :
"json"
,
type :
"post"
},
create : {
url : crudServiceBaseUrl +
"insertIndexItem"
,
contentType :
"application/json"
,
dataType :
"json"
,
type :
"post"
},
destroy : {
url : crudServiceBaseUrl +
"delIndexItem"
,
contentType :
"application/json"
,
dataType :
"json"
,
type :
"post"
After setting the above option, the project start working as expected on our side.
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!