1

Setup: I have two contextual filters, service area and ID.

In my view if I send {service_area}/{id} i get back the OR query, which is what I want. My question is, when I try to use Jquery to return this query, I do not get back the expected result, which is the OR of these two arguments.

Here is my code:

(function($) {
  Drupal.behaviors.searchresults = {
    attach: function (context, settings) {
      $('.currentFilters', context).once('search').click(function () {
        
        //hard set variable for this example.
        let args = [];
        args[0] = 'antelope valley';
        args[1] = '221';

        $.ajax({
          url: '/views/ajax',
          type: 'post',
          data: {
            view_name: 'webform_submissions',
            view_display_id: 'page_1',
            
            //This is where it may be causing an issue. I pass an array with the arguments, but no avail
            view_args: args,
          },
          ...
        });
      });
    },
  }
})(jQuery);

In my view I am able to see this OR if I preview with contextual filters as as seen in the image below:

enter image description here

If I just send service_area by itself as the argument, it will work. So my question is, what is the correct way of sending multiple arguments in ajax, any references/blogs to help me would be appreciated. Thank you!

1 Answer 1

0

I figured it out. I needed to pass a string not an object, the lack of documentation confused me.

    let args = 'antelope valley';
    args = args + '/207'

    $.ajax({
      url: '/views/ajax',
      type: 'post',
      data: {
        view_args: args,
 ...

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.