2

Jquery $.get should send single query string parameter _filters whose value is json string:

API/MyGet?_filters='{groupOp:"AND",rules:[{field:"Toode",op:"eq",data:"xxxx"}]}'&sort=code

I tried

$.get( 'API/MyGet',  {
   _filters:{ groupOp:"AND",
              rules:[{field:"Toode", op:"eq", data:'xxxx'}]
            },
   sort: 'code'
   },
   function(data) {
            alert( JSON.stringify(data) );
   }
   );

but Chrome developer tools show that this creates incorrect and strange query string:

_filters[groupOp]=AND&_filters[rules][0][field]=Toode&_filters[rules][0][op]=eq&_filters[rules][0][data]=

How to force jquery get to pass proper query string ?

6
  • Do you really need that "_filters" object? $.get( 'API/Entity/ToodeL', { groupOp:"AND", rules:[{field:"Toode", op:"eq", data:'xxxx'}] } Commented Sep 11, 2016 at 15:26
  • Yes. In real app query string has more parameters: page number, page size, sort order etc. _filters can contain more sophisticated search condition. So _filters must be single parameters whose value is json string. Commented Sep 11, 2016 at 15:28
  • @Developer I modified question. Added sort parameter also and changed _filters value to string Commented Sep 11, 2016 at 15:31
  • I might be wrong, but IMO the query string which is getting constructed in this is the way it should be. Could you please mention the format of query string you expect? Commented Sep 11, 2016 at 15:40
  • Short: you can't. This query string is generated by the $.serialize() method. You would need to extend the functionality of this method -or pre-process the query sting yourself i.e. $.get('path/to', 'filters={jsonstring}'); Commented Sep 11, 2016 at 15:41

1 Answer 1

1
var params = {
  sort: '...',
  _filters: JSON.stringify({
    'key': 'value'
  })
};

$.get('API/MyGet', params, function(data) {
  alert( JSON.stringify(data) );
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.