2012-03-02 23 views
1

誰かがラジオボタンで応答を変更するたびに、その情報がデータベースに記録されます。ここだapplication.jsファイル内のjavascript:ラジオボタンのHTMLではレンダリング:nothing => jqueryモバイルRails 3.0アプリでtrueが動作しない

$('.submittable').live('change', function() { 
    $(this).parents('form:first').submit(); 
    return false; 
}); 

は次のとおりです。

class="submittable" 

フルサイトでは、それはそうのようなコントローラに抑制されているため、ページの変更はありません。

def update_result 
    ... 
    render :nothing => true 
end 

しかし、モバイル版ではページがundefined左上隅にあるが、それ以外は白紙であると言うページに反転します。端末ウィンドウメッセージ:

... 
Processing by AnswersController#update_result as JS 
... 
Rendered text template (0.0ms) 
Completed 200 OK in 309ms (Views: 5.6ms | ActiveRecord: 5.1ms) 

ありがとうございます。

答えて

1

(そう何ページ-変更が発生していない)自分でフォームを送信するために、jQueryのモバイルを使用する場合は、我々は(フォームのsubmitコールバックで)私たち自身のAJAX機能を<form>タグにdata-ajax="false"を設定し、セットアップする必要があります。

//as of jQuery 1.7 `.live()` is depreciated in favor of `.delegate()` 
$(document).delegate('.submittable', 'change', function() { 

    //`.closest('form')` is the same as `.parent('form:first')`, also `.submit()` is shorthand for `.trigger('submit')`, just FYI 
    $(this).closest('form').trigger('submit'); 
    return false; 
}).delegate('form', 'submit', function() { 

    //cache the jQuery object of this form and use that variable to setup the AJAX request 
    var $form = $(this); 
    $.ajax({ 
     url  : $form.attr('action'),//use the form's action attribute for the URL of the request 
     type : $form.attr('method'),//use the form's method attribute to set the TYPE of the request 
     data : $form.serialize(),//add the form input data to the request 
     success : function (serverResponse) { 
      //the server has responded, whatever was output by the server-side script is available through the `serverResponse` variable 
     }, 
     error : function (jqXHR, textStatus, errorThrown) { 
      //make sure to handle errors 
     } 
    }); 

    return false; 
}); 

<form action="..." data-ajax="false" method="post"> 
    ... 
</form> 
+0

すべての作業に感謝します。私は論理を得ています。それは理にかなっていますが、もっと簡単な解決法があるのか​​疑問に思います。 – Jay

関連する問題