从jQGrid中为RESTFul Web服务删除额外的查询参数 [英] remove extra query parameters from jQGrid for RESTFul webservice

查看:213
本文介绍了从jQGrid中为RESTFul Web服务删除额外的查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JQGrid从我在服务器上创建的RESTFul web services中获取日期

I am using JQGrid to get the date from the RESTFul web services that i have created on the server

现在,当我尝试访问URL http://www.example.com/event/getAllInfo时,默认情况下jqGrid将_search=false&nd=1332922405416&rows=20&page=1&sidx=&sord=asc附加到其余URL,因此我的服务器不会取回数据,因此

now when i try to hit the url http://www.example.com/event/getAllInfo , the jqGrid by default appends _search=false&nd=1332922405416&rows=20&page=1&sidx=&sord=asc to the rest url and because of that my server don't fetch the data back , so

1)如何删除它
2)并以看起来像这样的方式将其放回url http://www.example.com/event/getAllInfo /false/1332922405416/20/1/0/asc

1) how can i remove it
2) and put it back in a url with in such a way that it looks http://www.example.com/event/getAllInfo/false/1332922405416/20/1/0/asc

我可以如上所述在服务器上创建url,但是如何使jQGrid从RESTful而不是查询字符串中使用它

i can create the url at the server as above but how can i make the jQGrid to use it from RESTful rather then from query string

这是我的代码

jQuery("#list4").jqGrid({
        url:"http://www.example.com/event/getAllInfo",
        datatype: "json",
        restful:  true,
        mtype: 'GET',
        height: 250,
        colNames:['id','title', 'description', 'create date','json','img','video'],
        colModel:[
            {name:'id',index:'e_info_id', width:60, sorttype:"int"},
            {name:'title',index:'e_meta_title', width:90, sorttype:"date"},
            {name:'name',index:'e_meta_description', width:100},
            {name:'amount',index:'e_info_create_date', width:80, },
            {name:'tax',index:'e_meta_JSON', width:80},     
            {name:'total',index:'e_meta_img', width:80},        
            {name:'note',index:'e_meta_video', width:150}       
        ],
        multiselect: true,
        caption: "Manipulating Array Data"
    });

推荐答案

首先,RESTFul Web服务并不意味着您无法将其他参数发送到服务器.主要想法是仅使用URL来标识资源并使用不同的HTTP动词(请求方法)进行不同的操作.

First of all the RESTFul web services don't mean that you can't send additional parameters to the server. The main idea only to use URL to identify the resource and use different HTTP verbs (request methods) for different operations.

仅当您不想或不能实现服务器端页面调度,数据排序和过滤时,才可以从将要使用的URL中删除任何其他参数.为此,您只需添加

Only if you don't want or don't can to implement server side paging, sorting and filtering of data you can remove any additional parameters from the URL which will be used. Do do this you can just add

postData: ""

作为附加参数.在这种情况下,您应该使用loadonce: true或至少使用rowNum: 10000(或其他较大的值).在这种情况下,使用gridview: true作为附加参数非常重要(我建议始终使用该参数).服务器应返回 all 数据.如果要使用sortname参数,则应对数据进行排序.

as additional parameter. In the case you should use loadonce: true or at least rowNum: 10000 (or some other large value). In the case will be very important to use gridview: true as additional parameter (I recommend to use the parameter always). The server should return all the data. The data should be sorted if you would use sortname parameter.

我建议您将Cache-Control: private, max-age=0添加到服务器响应的标头中(请参见此处此处).

I would recommend you to add Cache-Control: private, max-age=0 to the header of the server response (see here and here).

已更新:我建议您阅读有关所问问题的答案 URL的编码.就像我之前在评论中给您写的一样,我认为_search=false&rows=20&page=1&sidx=&sord=asc部分不属于资源.它主要是请求的其他选项或属性.您可以将信息放在 loadBeforeSend 回调(请参见此处示例),但我认为这不是一个好主意,并且可以简化您开发的RESTfull服务的使用情况.我建议您就prmNames: {nd: null} jqGrid选项删除nd=1332922405416并使用Cache-Control控制缓存或响应.

UPDATED: I recommend you to read the answer on the question which you ask about the encoding of the URL. Like I wrote you before in the comment I think that the part _search=false&rows=20&page=1&sidx=&sord=asc is not belong to resource. It's mostly an additional options or properties of the request. You can place the information in the HTTP header inside of loadBeforeSend callback (see here an example), but I don't think that it will be good idea and will simplify the usage of the RESTfull services which you develop. I would recommend you just remove nd=1332922405416 with respect of prmNames: {nd: null} jqGrid option and use Cache-Control to control the caching or responses.

这篇关于从jQGrid中为RESTFul Web服务删除额外的查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆