admin管理员组文章数量:1323737
I got RJS error: TypeError: element is null while using ajax.
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
<% if [email protected]? && !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}"},
:plete=>"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
<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
I got RJS error: TypeError: element is null while using ajax.
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
<% if [email protected]? && !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}"},
:plete=>"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
<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
Share Improve this question edited Mar 19, 2010 at 5:03 Jordan Running 106k18 gold badges188 silver badges187 bronze badges asked Mar 19, 2010 at 4:48 SalilSalil 47.5k22 gold badges125 silver badges160 bronze badges 1- Element is null means that there is DOM element on the page that the returned javascript is trying to access that cannot be found. I cannot see the issue immediately, but that is what the error means. – Apie Commented Mar 19, 2010 at 6:22
2 Answers
Reset to default 4I find it out why it happens because I didn't close div above the "chat_area" properly. the only thing i did isclose the div and it works like a magic, neways thanks to all
Reagrds,
Salil Gaikwad
This means that RJS is attempting to manipulate something in html output that doesn't exist.
It looks like the problem is that you want to update your user_list
but nothing with that id exists in your html. 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(:url => { :action => 'get_user_list' }, :update => 'get_user_list')
本文标签: javascriptRJS error TypeError element is nullStack Overflow
版权声明:本文标题:javascript - RJS error: TypeError: element is null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742114548a2421407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论