I worked in printing out a view using php. Is it possible to fetch views using ajax and load in the page? For suppose I have three links each one will fetch a view using ajax and load in the current page. (Am I talking sense?)

2 Answers 2


Yes it is very much possible, but probably you can do it only by creating custom module.

  • send Ajax request to the Drupal
  • load selected view form database by views_get_view
  • execute selected display by $view->execute_display('display')
  • send HTML created on executing display back to the client.
  • on client side put this html wherever you want

Check ajax load module (which is D6 only) too, maybe it can help you.

There is a even quicker way and more robust to render a view: views_embed_view

  • I'm new to drupal 7, how do I can send ajax request to the Drupal? where must be the javascript file? and where musst be the server side code?
    – M a m a D
    Commented Jan 25, 2014 at 16:00
  • @Mohammad use google Luke ;)
    – Codium
    Commented Jan 25, 2014 at 18:55

Use the following javascript code to load a view via ajax.

Drupal.settings.basePath + 'views/ajax',

view_name: '<your view id>',view_display_id: '<page or block ...>',view_args: 'arg1/arg2..'

    if (response[1] !== undefined) 
        var viewHtml = response[1].data;
  • This worked for me, however be careful with the Drupal.attachBehaviors() call at the end. It caused some problems for me. I removed it as it's not needed for my simple non-paged view.
    – kmcl
    Commented Oct 24, 2014 at 21:29

Your Answer

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

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