1

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

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) 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

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

here is my code

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"
    });
Hunt
  • 8,215
  • 28
  • 116
  • 256

1 Answers1

3

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.

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: ""

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.

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

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • by using postData="" i can eliminate the extra params or query string but how can i replace `search=false&nd=1332922405416&rows=20&page=1&sidx=&sord=asc` in a rest style as i have shown in my question so that i can still take benefit of rest and paging – Hunt Mar 28 '12 at 09:15
  • @Hunt: Sorry, by you misunderstand RESTFull concept of resources as URL. You have only one resource `http://www.example.com/event/getAllInfo`. The "false" is not sub-resource and the timestamp 1332922405416 is also not a sub-resource and so on. Only the part of URL which correspond some resource should be encoded in hierarchical way. You can still send some URL parameters which are additional information to your request. – Oleg Mar 28 '12 at 09:21
  • so sending query string with a url is not a violation of RESTFul url convention ? – Hunt Mar 28 '12 at 09:24
  • @Hunt: I don't think so. I am not dogmatist. You should just get the best from the technology which you use. Is it really important for the user whether you strictly follow some interpretation of RESTfull services? The most users don't know the words at all. It's important just use HTTP GET correctly to allow web browser or proxy to cache the information which you need cache and use HTTP DELETE or HTTP POST for requests which should be not cached. In any way I recommend you to use `prmNames: {nd: null}` and control caching by HTTP headers. – Oleg Mar 28 '12 at 09:33
  • @Hunt: By the way [the answer](http://stackoverflow.com/a/7365228/315935) could be probably helpful for you. – Oleg Mar 28 '12 at 09:41