jquery - The AJAX request don't load the js of the response action -
i have problem js response of action. i'm implementing im polling , redis. "problem" found in moment submit message. want button (normal way) or via enter. when form submit button works correctly: create message , other user see message in screen , message appears screen via create.js, prepends last message sent screen. when submit form enter key works (send message , other recieve @ moment) except create.js, reason create.js it's loaded don't execute action of prepend last message screen. put code below, in advance ;).
create.js
$(".conversations").prepend("#{escape_javascript(render partial: 'dashboard/kid_conversations/show_message', locals: { message: @message})}"); $("#kid_conversation_message_body").val(""); this js permit enter submit:
setinterval(function(){ $.ajax({ url: "#{dashboard_kid_conversation_conversation_polling_url(current_kid, token: (params[:token] rescue nil))}", })},2000); $('#kid_conversation_message_body').keypress(function(e) { if (e.keycode == 13 && !e.shiftkey) { e.preventdefault(); $.ajax({ url: "#{dashboard_kid_conversation_messages_url}", type: "post", data: $(this).serialize() + "&conversation_token=" + "#{params[:token]}", success: $("#kid_conversation_message_body").val(""), datatype: "json" }); } }); the final logs when enter key, create.js loaded.
rendered dashboard/kid_conversations/_show_message.html.haml (6.5ms) rendered dashboard/kid_conversation_messages/create.js.haml (11.4ms) completed 200 ok in 287ms (views: 270.8ms) the create action:
def create @message = kidconversationmessage.new(params[:kid_conversation_message]) @message.kid_conversation = @conversation @message.kid = current_kid @message.save end the form, use haml
.response = form_for [:dashboard, @message] , html: {remote: true}do |f| = hidden_field_tag :conversation_token, :body , :value=> @conversation.token .control-group = f.label :body, _('reply') = f.text_area :body, :rows => 4 = submit_tag _('send'), :class => 'btn button'
it looks me form submits dashboard_messages_url, while keypress function ajax posts dashboard_kid_conversation_messages_url. check routes make sure latter exists.
if doesn't work might tell you're seeing in network tab of web inpsector.
Comments
Post a Comment