Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

 1 Answer(s)

  • As you enter the student name call a javascript function to execute the ajax call then, Set the element that will receive the AJAX callback, like:

    <div id="ajax-target">Ajax goes here!!!</div>
    

    After that goto the custom code:

    1--> Create a JavaScript function that will handle the call using jQuery.load(). The $nid in the path is just an example. It could be any variable.

    <script>
            function myModule&#95;ajax&#95;load(name) {
              jQuery("#ajax-target").load("/node/ajax/"+name);
            }
        </script>
    

    Note: please use _ in place of &#95; in above code



    Write code in custom module:

    2--> Register the URL that will render the HTML by implementing hook_menu():

        function myModule_menu() {
            $items['node/ajax/%'] = array(
                'page callback' => 'myModule_ajax_get_ajax', // Render HTML.
                'page arguments' => array(2),
                'type' => MENU_CALLBACK,
                'access arguments' => array('access content'),
                'delivery callback' => 'myModule_ajax_callback',  // Magic goes here.
            );
            return $items;
        }
    



    3--> Create page callback and delivery callback functions:

    function myModule_ajax_get_ajax($nid) {
            // You can return whatever you want, including forms.
            $node = node_load($nid);
            return node_view($node, 'teaser');
        }
    
        function myModule_ajax_callback($page_callback_result) {
            // Only render content
            $content = drupal_render($page_callback_result);
    
            // Add CSS and JS files, add some html
            $html = '' . drupal_get_css() . drupal_get_js() . '' . $content . '';
            print $html;
    
            // Perform end-of-request tasks.
            drupal_page_footer();
        }
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: