问题描述
我需要拥有当前选择的行 id 才能构建一个 JSON 字符串,该字符串将传递给 php 脚本以创建选择,因此我将脚本引用和代码包含在一个函数中.
I need to have the currently selected row id in order to build a JSON string that will be passed to a php script in order to create a select, so I enclosed the script reference and code in a function.
但是,这样做会产生 NetworkError: 403 Forbidden
错误.
However, doing so creates a NetworkError: 403 Forbidden
error.
这里是代码段:
editoptions:{dataUrl:function(){
var row_id = $('#tab3-grid').getGridParam('selrow');
var jsondata = JSON.stringify({"cu.STID": $('#tab3-grid').jqGrid('getCell', row_id, 'cu.STID'),
"wv.SVID": $('#tab3-grid').jqGrid('getCell', row_id, 'wv.SVID')});
return 'php/items-se-script.php?data='+jsondata;
},
有人知道怎么回事吗?
更新:
{name:'it.PRID', index:'it.PRID', hidden: true, editable:true, edittype:'select',
editoptions:{dataUrl:'php/items-se-script.php', defaultValue:'26', dataEvents:[{type:'change',fn:function(e){$('input#ip\.Item').val($('option:selected', this).text());}}]},
formoptions:{label:'Item', elmprefix:'* '},
editrules:{edithidden:true, required:true}},
{name:'ip.Item', index:'ip.Item', hidden: true, sortable: true, editable:false, edittype:'text', editoptions:{readonly:true,size:20}, formoptions:{rowpos: 50, label:'Item'}, editrules:{required:true}}
],
ajaxSelectOptions: {
type:'POST',
data: {
data: function () {
var row_id = $('#tab3-grid').getGridParam('selrow');
return JSON.stringify({
"cu.STID": $('#tab3-grid').jqGrid('getCell', row_id, 'cu.STID'),
"wv.SVID": $('#tab3-grid').jqGrid('getCell', row_id, 'wv.SVID')
});
}
}
},
url: 'php/workordertab-script.php',
editurl:'php/workordertab-script.php',
推荐答案
属性 dataUrl
不能是函数.如果您需要在构建选择期间向服务器发送任何其他信息,您可以使用 ajaxSelectOptions 选项,就像我在 这里.在您的情况下,它将与以下内容有关:
The property dataUrl
can't be a function. If you need to send any additional information to the server during building of select you can use ajaxSelectOptions option like I described as here. In your case it will be about the following:
var $myGrid = $('#tab3-grid');
$myGrid.jqGrid({
// ... here all you current parameters which includes
// editoptions: { dataUrl: 'php/items-se-script.php' }
// for the corresponding column in colModel
ajaxSelectOptions: {
data: { // "data" here is jQuery.ajax parameter
data: function () { // "data" here is the name of you custom parameter
var row_id = $myGrid.getGridParam('selrow');
return JSON.stringify({
"cu.STID": $myGrid.jqGrid('getCell', row_id, 'cu.STID'),
"wv.SVID": $myGrid.jqGrid('getCell', row_id, 'wv.SVID')
});
}
}
}
});
这篇关于jqgrid dataUrl函数代码段有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!