jqGrid navGrid无法使用jquery向数据库添加记录 [英] jqGrid navGrid not able to add record to database using jquery
问题描述
你好朋友,
我正在使用jqGrid的navGrid功能向数据库添加记录.
我的问题是:调用服务器端函数将记录保存到数据库的正确方法是什么.我正在使用ajax功能来保存记录.我可以先调用ajax函数,然后再调用服务器端代码.
如何将返回值传递回jqgrid.我收到错误消息:错误状态:"未找到".错误代码:404"
我的代码是:
Hello friends,
I am using navGrid feature of jqGrid to add record to database.
My question is: What is the correct way to call server side function to save record to database. I am using ajax fucntion to save record. I am able to call the ajax function and then server side code.
How to pass return value back to jqgrid. I am getting error: "error Status: ''Not Found''. Error code: 404"
My code is:
jQuery("#list").jqGrid({
datatype: "jsonstring",
contentType: "application/json; charset=utf-8",
..........
..........
}).navGrid('#pager',
{add:true,edit:true,del:true,search:true,refresh:true}, // which buttons to show?
{editCaption: 'Update Environment', beforeSubmit: validateEditData, afterSubmit: processEdit }, // edit options
{addCaption: 'New Environment', onclickSubmit: processAdd }, // add options
{delCaption: 'Delete Row', beforeSubmit: validateDeleteData, afterSubmit: processDelete} // delete options
);;
我正在像这样的"processAdd"函数中调用我的ajax函数:
I am calling my ajax function in "processAdd" function like this:
$.ajax({
url: 'Environments.aspx/AddNewEnvironment',
data: Environment,
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
success: function (data) {
.....
.....
return [dat.result, dat.message];
},
有人可以告诉我如何使用navGrid功能添加记录吗?要一步一步来吗?"
问候
Can any one tell me "How to add record using navGrid functionality? step by step?"
Regards
推荐答案
.ajax({ 网址:' Environments.aspx/AddNewEnvironment', 数据:环境, contentType:" , dataType:" , 类型:" , 成功:功能(数据){ ..... ..... 返回 [dat.result,dat.message]; },
.ajax({ url: 'Environments.aspx/AddNewEnvironment', data: Environment, contentType: "application/json; charset=utf-8", dataType: "json", type: "POST", success: function (data) { ..... ..... return [dat.result, dat.message]; },
有人可以告诉我如何使用navGrid功能添加记录吗?要一步一步来吗?"
问候
Can any one tell me "How to add record using navGrid functionality? step by step?"
Regards
您需要像这样重新绑定JQGrid:
您可以设置页面和方法名称以获取数据,例如
Hi,
You need to rebind JQGrid like:
you can set your Page and Method name for getting data for example
url: 'Environments.aspx/GetEnvironmentList'
以下是 JQGrid
的完整代码
Following is whole code for JQGrid
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '@Url.Action("JQGridGetGridData", "TabMaster")',
datatype: 'json',
mtype: 'GET',
colNames: ['col ID', 'First Name', 'Last Name', ''],
colModel: [
{ name: 'colID', index: 'colID', width: 100, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
{ name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true, editrules: { required: true} },
{ name: 'LastName', index: 'LastName', width: 150, align: 'left', editable: true },
{ name: 'Edit', index: 'Edit', width: 70, align: 'center', editable: false, formatter: editFmatter, unformat: unformatEdit }
],
pager: jQuery('#pager'),
hidegrid: false,
rowNum: 100,
rowList: [10, 50, 100, 150],
sortname: 'colID',
sortorder: "asc",
viewrecords: true,
multiselect: false,
imgpath: '@Url.Content("~/Scripts/themes/steel/images")',
caption: 'Tab Master Information',
editurl: '@Url.Action("JQGridEdit", "TabMaster")'
}).navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: false });
});
如果您想要更多帮助,请随时问我.
谢谢,
Imdadhusen
If you would like to more help for that please feel free to ask me.
Thanks,
Imdadhusen
这篇关于jqGrid navGrid无法使用jquery向数据库添加记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!