2014-12-03 148 views
0

主网格代码是下面如何传递带有空格的参数值的URI?在的jqGrid

$(document).ready(function() { 
    jQuery("#list5").jqGrid({ 
     url: 'server.php?mode=getBaseList', 
     datatype: "json", 
     colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'], 
     colModel: [{ 
      name: 'id', 
      index: 'id', 
      width: 55 
     }, { 
      name: 'invdate', 
      index: 'invdate', 
      width: 90 
     }, { 
      name: 'name', 
      index: 'name', 
      width: 100 
     }, { 
      name: 'amount', 
      index: 'amount', 
      width: 80, 
      align: "right" 
     }, { 
      name: 'tax', 
      index: 'tax', 
      width: 80, 
      align: "right" 
     }, { 
      name: 'total', 
      index: 'total', 
      width: 80, 
      align: "right" 
     }, { 
      name: 'note', 
      index: 'note', 
      width: 150, 
      sortable: false 
     }], 
     rowNum: 10, 
     jsonReader{ 
     id:'id',repeatitems:false 
     }, 
     rowList: [10, 20, 30], 
     pager: '#pager5', 
     sortname: 'name', 
     autoencode: true, 
     loadonce:true, 
     sortable: true, 
     viewrecords: true, 
     sortorder: "desc", 
     multiselect: false, 
     subGrid: true, 
     subGridRowExpanded: function(subgrid_id, row_id) { 
     var newID = $('#list5').getCell(row_id, 'id'); 
     var escapeID=escape(newID); 

     var subgrid_table_id, pager_id; 
     subgrid_table_id = subgrid_id+"_t"; 
     pager_id = "p_"+subgrid_table_id; 
     $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
     jQuery("#"+subgrid_table_id).jqGrid({ 
     url:"/portal/getSubGridData?id="+escapeID, 
     datatype: "json", 
     colNames: ['No','Item','Qty','Unit','Line Total'], 
     colModel: [ 
     {name:"num",index:"num",width:80,key:true}, 
     {name:"item",index:"item",width:130} 
     ], 
     rowNum:20, 
     pager: pager_id, 
     sortname: 'num', 
     sortorder: "asc", 
     height: '100%' 
     }); 
     jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false}) } 
     caption: "Simple data manipulation" 
    }).navGrid("#pager5", { 
     edit: false, 
     add: false, 
     del: false 
    }); 
}); 
jQuery("#list5").jqGrid('filterToolbar',{searchOperators : true}); 

如何通过URI具有空间参数值?我观察到JS中取消了'%20'或'_'。我该怎么办?

我想: 第1步:使用ID

id=10054898 104143018 

var modifiedUrl=escape(id); 

新的URL如下

我的网址是低于

newUrl=/portal/getSubGridData?id=10054898%20104143018 

第2步:使用名称

name=John Williams 

var modifiedUrl=escape(name); 

如下

我的网址是

newUrl=/portal/getSubGridData?name=John%20Williams 

上述网址不发布到服务器端新的URL,我已经检查萤火虫。网址未被提交。

+0

试图发出POST请求时会出现什么错误? – 2014-12-03 12:02:53

+0

你使用的JavaScript代码在哪里?如果你使用'postData',这个问题根本不应该存在。可以使用'encodeURIComponent'或使用jQuery的$ .param'方法。如果您发布** JavaScript代码,您可以使用相应的示例发布我的答案。 – Oleg 2014-12-03 12:04:36

+0

我有使用post方法(mtype是post)。但服务器端没有得到数据提供 – 2014-12-03 12:05:00

回答

0

我想你使用Subgrid as Grid并创建子网格的代码一样

subGridRowExpanded: function(subgridId, rowId) { 
    var id = $.jgrid.stripPref(this.p.idPrefix, rowId); 
    ... 
    $subgrid.jqGrid({ 
     url: "/portal/getSubGridData?id=" + id, 
    }); 
    ... 
} 

你应该从未添加常见字符串值作为URL的一部分。相反的,你应该使用标准的JavaScript方法encodeURIComponent

 url: "/portal/getSubGridData?id=" + encodeURIComponent(id), 

或jQuery.param方法

 url: "/portal/getSubGridData?" + $.param({id: id}), 

更容易将使用

 url: "/portal/getSubGridData", 
     postData: { 
      id: id 
     } 

在这种情况下的ID将被添加到其他参数,这些参数将被发送到服务器,并且我希望您能够在服务器端进行分析。如果您使用HTTP GET,则可以使用PHP中的$_GET访问参数。如果你使用mtype: "POST",那么你使用$_POST(有些像$_POST["id"])访问参数。我不是PHP开发人员,但我不明白为什么可以将一些参数附加到URL并使用标准方式发布另一个参数:HTTP POST请求正文内部。

最后一句:我强烈建议你不要在id中使用空格。取决于您使用的是哪个版本的HTML 可能会被禁止。我建议你最好使用下划线而不是空格。