简体   繁体   English

RJS错误:TypeError:元素为空

[英]RJS error: TypeError: element is null

I got RJS error: TypeError: element is null while using ajax. 我收到RJS错误:TypeError:使用Ajax时元素为null。

I used in view 我用过的

<%= periodically_call_remote(:url=>{:action=>'get_user_list', :id=>'1'},
:frequency => '5') %>

in controller 在控制器中

  render :update do |page|
    page.replace_html  'chat_area', :partial => 'chat_area', :object => [@chats, @user]     if @js_update
  end

in partial chat_area 在部分chat_area中

<% if !@chats.blank? && !show_div(@chats).blank?%>
    <% show_div_id=show_div(@chats) %>
  <% for chat in @chats %>
      <div class="popup" id="chat_area_<%= chat.id %>"
style="display:<%= (chat.id == show_div_id)? 'block' : 'none' %>;">

        <% form_remote_for(:chat, :url => {:controller=>'chats',
:action=>'create', :id=>1}, :html=>{:name => "form_#{chat.id}"},
:complete=>"resetContent('#{chat.id}');") do |f| %>
        <div style="display:none;">
            <%= f.hidden_field :sessionNo, :value=>chat.sessionNo %>
            <%= f.text_area :chatContent,  :id=>
"chatContent_field_#{chat.id}", :cols=>"100", :rows=>"6",
:onKeyPress=>"return submitenter(this,event);" %>
          </div>
            <input type="image" src="images/chat/send-hover.png"
value="Send" onclick="return submit_button('<%= chat.id %>')"/>
        <% end %>
      </div>

    </div>
  <% end %>

<% else %>
      <div class="popup" id="chat_area_none" style="display:'block';">
          <input type="image" disabled ="disabled"
src="images/chat/send.png" style="cursor:default;" value="Send" />
      </div>
<% end %>

My div present in index.html.erb 我的div存在于index.html.erb中

      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tbody><tr>
            <td align="left" width="80%" valign="top" style="">
              <%= text_area :chat, :chatContent,  :id=> "chatContent_field", :cols=>"100", :rows=>"6" %>
            </td>
            <td align="left" width="20%" valign="bottom" style="padding-left:10px;padding-left:10px;x" >
              <div id="chat_area">
                 <%= render :partial => 'chat_area' %>
              </div>
            </td>
          </tr>
        </tbody>
      </table>

Any help is appreciated. 任何帮助表示赞赏。

Regards, 问候,

Salil Gaikwad 萨里尔·盖克瓦德(Salil Gaikwad)

I find it out why it happens because I didn't close div above the "chat_area" properly. 我发现了发生这种情况的原因,因为我没有正确关闭“ chat_area”上方的div。 the only thing i did isclose the div and it works like a magic, neways thanks to all 我唯一要做的就是关闭div,它就像魔术一样工作,这要归功于所有人

Reagrds, Reagrds,

Salil Gaikwad 萨里尔·盖克瓦德(Salil Gaikwad)

This means that RJS is attempting to manipulate something in html output that doesn't exist. 这意味着RJS试图处理html输出中不存在的内容。

It looks like the problem is that you want to update your user_list but nothing with that id exists in your html. 看来问题在于您想更新user_list但html中没有该ID的内容。 Make sure you are rendering that, also make sure you have the update attribute in your periodically_call_remote method set to the id of the element you want to update. 确保正在渲染,还请确保已将periodically_call_remote方法中的update属性设置为要更新的元素的ID。

periodically_call_remote(:url => { :action => 'get_user_list' }, :update => 'get_user_list')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RJS的Rails类型错误? - rjs type error in rails? RJS:检查现有的页面元素? - RJS: Check for existing page element? Javascript:获取Typeerror-元素为null - Javascript: Get Typeerror - element is null JSON 对象:类型错误:元素为空 - JSON object: TypeError: element is null 接收错误消息:“未捕获的TypeError:尝试将focus()调用到元素ID时无法读取null的属性&#39;焦点&#39; - Receiving Error Message: “Uncaught TypeError: Cannot read property 'focus' of null” when trying to call focus() to an element ID JavaScript引发错误“未捕获的TypeError:无法将属性&#39;value&#39;设置为null”但元素存在 - JavaScript is throwing error “Uncaught TypeError: Cannot set property 'value' of null” yet element is present MooTools中的扩展元素给出错误“未捕获的TypeError:无法调用方法&#39;set&#39;为null” - Extending Element in MooTools gives error “Uncaught TypeError: Cannot call method 'set' of null” 错误类型错误:无法获取未定义或 null 参考的属性“0” - 当在控制台中的 HTML_Element 上单击()时 - ERROR TypeError: Unable to get property '0' of undefined or null reference - When click() on a HTML_Element in the Console TypeError:this.element为null,Rails与Judge gem - TypeError: this.element is null, Rails with Judge gem “类型错误:元素为空”。 在 javascript 中调用 getElementById 时 - 'TypeError : element is null'. when invoke the getElementById in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM