AJAX call with jQuery query string with duplicate keys

Apache Solr asks that one of the GET parameters sent to it is a duplicate name:

facet.range=price&facet.range=age 

The documentation is here:

http://wiki.apache.org/solr/SimpleFacetParameters#facet.range

In jQuery, how can I double-enable this query string parameter ( facet.range )? I cannot create an object with duplicate keys, but this corresponds to what I need to do:

 context = { 'facet.range': 'price', 'facet.range': 'age', // This will be the only element in this dictionary as the key names are the same } $.ajax({ type: "get", url: 'http://127.0.0.1:8983/solr/select', dataType:"jsonp", contentTypeString: 'application/json', jsonp:"json.wrf", data: context, success:function (data) { ... } }); 
+6
source share
5 answers

Use 'facet.range': ['price', 'age'] in your params object and set the traditional parameter to true in the ajax call to provide a โ€œtraditionalโ€ parameter serialization, that is, foo=1&foo=2 instead of foo[]=1&foo[]=2 .

+11
source

jQuery internally uses $.param to serialize forms, so you can do the same:

 data = $.param( { name: 'facet.range', value: 'price' }, { name: 'facet.range', value: 'age' } ) 
+3
source

You can add arguments manually to the URL.

  $.ajax({ type: "get", url: 'http://127.0.0.1:8983/solr/select?facet.range=price&facet.range=age', // Add other parameters in the url dataType:"jsonp", contentTypeString: 'application/json', jsonp:"json.wrf", success:function (data) { ... } }); 
+2
source

I think the only way is to "hard-code" the data as query string parameters, and not pass data

 $.ajax({ type: "get", url: 'http://127.0.0.1:8983/solr/select?facet.range=price&facet.range=age', dataType:"jsonp", contentTypeString: 'application/json', jsonp:"json.wrf", data: null, success:function (data) { ... } }); 
0
source

I am not familiar with Apache Solr, but I know that you can simply re-create the URL to pass the parameters

 $.ajax({ type: "get", url: 'http://127.0.0.1:8983/solr/select?'+ "facet.range=price&facet.range=age", success:function (data) { ... } }); 
-1
source

Source: https://habr.com/ru/post/925932/


All Articles