Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

php - having trouble with jqgrid dataUrl function code segment

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.

However, doing so creates a NetworkError: 403 Forbidden error.

Here is the code segment:

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;
},

Does anyone know whats going on?

UPDATE:

{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',
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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')
                });
            }
        }
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...