Last active
October 23, 2015 09:08
-
-
Save guoxiangke/442b91e8b9905aaa5429 to your computer and use it in GitHub Desktop.
drupal views Ajax get views update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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