我的application.js document.ready函数被调用了两次 [英] My application.js document.ready function is called twice

查看:119
本文介绍了我的application.js document.ready函数被调用了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails应用程序中,我试图在application.js脚本中调用document.ready函数以实现自动完成.此函数在重新加载文件时被调用两次.即使我不包含= javascript_include_tag:defaults ,:cache => true,它调用一次,如果包含两次调用.正因为如此,我传递的值被替换为null.有人知道为什么它调用了两次吗?

In my rails application,I am trying to call the document.ready function in application.js script for my auto complete.This function is called twice on reloading the file.i.e even if i don't include = javascript_include_tag :defaults,:cache => true its called once and if its included its called twice. Because of this the value I am passing is replaced with null.Any idea why its called twice?

   %td.grid.full_panels
    -table_panel "Assign Testers" do
      %table
        %th Name
        -puts "testers=#{@testers}"
        = form.label :tester_tokens, "Testers" 
        = form.text_field :tester_tokens
        - @testers.each do |tester|
          %tr
            %td=tester.name
            %td=check_box_tag "release[tester_ids][]", tester.id,   @release.is_tester_assigned(tester)
      //=will_paginate @testers
-@names=["sramya","scharron"]
:javascript
var data='#{escape_javascript @names.to_json.html_safe}' 
= javascript_include_tag :defaults,:cache => 

我的application.js文件:

My application.js file:

 $(document).ready(function() {

console.log("inside application");
data1='["sramya","scharron"]';
console.log("before parsing"+data+",data1="+data1);
data=$.parseJSON(data);
data1=$.parseJSON(data1);
//console.log(data1);
console.log("after parsing"+data+",data1="+data1);
$('#release_tester_tokens').autocomplete({source:data1}); 


 });

推荐答案

有时,firebug可能会触发DOM就绪事件,例如两次发布以跟踪网络.尝试打开萤火虫

Sometimes firebug may fire DOM ready event like double post to track net. Try to turn of firebug

这篇关于我的application.js document.ready函数被调用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆