return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>How to reload the custom JavaScript file after Drupal makes ajax call? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to reload the custom JavaScript file after Drupal makes ajax call? - Stack Overflow

programmeradmin2浏览0评论

How one can reload the custom JavaScript file after an Ajax call is pleted?

In my case I have a custom JavaScript file to manipulate the views data and filters. It works perfectly the first time a page is loaded.

But once the user sets a filter and hits Apply i.e. after the Ajax call, the JavaScript seems to stop working. It's there but not registering any event.

I read some articles on Drupal but that didn't give me a solid solution.

Note - Its not a module .js file but a custom stand alone .js file under the theme folder.

How one can reload the custom JavaScript file after an Ajax call is pleted?

In my case I have a custom JavaScript file to manipulate the views data and filters. It works perfectly the first time a page is loaded.

But once the user sets a filter and hits Apply i.e. after the Ajax call, the JavaScript seems to stop working. It's there but not registering any event.

I read some articles on Drupal but that didn't give me a solid solution.

Note - Its not a module .js file but a custom stand alone .js file under the theme folder.

Share Improve this question edited Mar 22, 2016 at 17:51 gariepy 3,6846 gold badges23 silver badges34 bronze badges asked Jul 28, 2010 at 20:15 jainchetanjainchetan 961 silver badge9 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You should read up on JavaScript in Drupal, especially any part about Drupal.bahaviors.

The main point is that you need to turn your custom JavaScript file into Drupal.behaviors, because those will get reattached to content loaded dynamically via AJAX like calls.

the question could be - "how can I fire a js function with updated on a dupal call back parameters"

this is what I did:

my form like this:

$form['letterdrop_id'] = array(                       
    '#type' => 'select',                              
    '#title' => 'Letterdrops',                        
    '#options' => $letterdrops,                       
    '#prefix' => '<div id="replace_div_ld">',         
    '#suffix' => '</div>',                            
    '#ajax' => array(                                 
      'callback' => 'agc_ems_form_map_change',        
      ),                                              
    );                                                

with this call back function:

function agc_ems_form_map_change($form, &$fstate) {              
   return array(                                                 
    '#type' => 'ajax',                                           
    '#mands' => array(
      // this mand is to reload a form element                                        
      ajax_mand_replace("#agc_map", render($form['map'])),    
      // this mand does the business and calls my custom function, 
      // with a parameter object supplied
      array('mand' => 'afterAjaxCallbackExample',             
          'selectedValue' => 'i am not a fish',                  
    )                                                            
  ));                                                            
}                                                                

this is my js function

(function($, Drupal) {                                                      
  // put function into drupal mands:   
  Drupal.ajax.prototype.mands.afterAjaxCallbackExample = 
     function(ajax, response, status) {
    // response object as passed in our Ajax callback          
    // do what you want in here
    alert(response.selectedValue);                                          
  };                                                                        
}(jQuery, Drupal));      

100% credit to jaypan

To add a script you need to use document.createElement("script") you can't just set innerHTML. see http://www.phpied./javascript-include-ready-onload/ for a good example that deals with seperate browsers.

发布评论

评论列表(0)

  1. 暂无评论