Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
Last active October 23, 2015 09:08
Show Gist options
  • Save guoxiangke/442b91e8b9905aaa5429 to your computer and use it in GitHub Desktop.
Save guoxiangke/442b91e8b9905aaa5429 to your computer and use it in GitHub Desktop.
drupal views Ajax get views update
<div id="views">views!!!begin!!!
<?php
print views_embed_view('foodbanks', 'block', $state);
?>
<a href="##" id= "freash" >freash!!!</a>
<script type="text/javascript">
(function($) {
function getInfo(args) {
$.ajax({
url: 'http://milklife.local/?q='+Drupal.settings.basePath + 'views/ajax',
type: 'post',
data: {
view_name: 'foodbanks',
view_display_id: 'block', //your display id
view_args: args,
},
dataType: 'json',
success: function (response) {
if (response[1] !== undefined) {
var viewHtml = response[1].data;
$('#views').html(viewHtml);
Drupal.attachBehaviors(); //check if you need this.
}
}
});
}
$('#freash').click(function(){
getInfo('WY');
});
})(jQuery);
</script>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment