Hi!

I'm trying pass one argument from JS to a View. If I type this in at the Views preview, it works fine and I get some result. By passing the same chars (I've tried it with colsole.log()) I've got the "empty result".

Here is my JS code:

var someDate = $(this).attr('id').slice(7,17); // the result format is: 2017-03-03, and it works in the preview

$.ajax({
	url: Drupal.settings.basePath +'/views/ajax',
	type: 'POST',
	data: {
		view_name: 'naptar',
		view_display_id: 'block_spec',
		args: someDate,
	},
	dataType: 'json',
	success: function(response) {
		if (response[1] !== undefined) {
			var viewHtml = response[1].data;
			$('#block-views-naptar-block-2').html(viewHtml);
		}
	},
	error: function(data) {
		$('#block-views-naptar-block-2').html('<p>An error occurred...</p>');
	}
});

With Firebug I see so, that my AJAX POST is

args:	2017-02-24
view_display_id:	block_spec
view_name:	naptar

the URL looks like view_name=naptar&view_display_id=block_spec&args=2017-02-24, but in the JSON response 0 -> settings -> views -> ajaxViews -> view_dom_id:xxx -> view_args is empty.

What do I wrong?

Thanks

Comments

pal_ur created an issue. See original summary.

pal_ur’s picture

There is the mistake:

$.ajax({
	url: Drupal.settings.basePath +'/views/ajax',
	type: 'POST',
	data: {
		view_name: 'naptar',
		view_display_id: 'block_spec',
		view_args: someDate,
	},
	dataType: 'json',
	success: function(response) {
		if (response[1] !== undefined) {
			var viewHtml = response[1].data;
			$('#block-views-naptar-block-2').html(viewHtml);
		}
	},
	error: function(data) {
		$('#block-views-naptar-block-2').html('<p>An error occurred...</p>');
	}
});

In data {} use view_args instead if args.

pal_ur’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.