|
Post by fnllc on Jul 25, 2018 1:45:51 GMT
I'm trying to figure out how to submit a form through ajax in Rhomobile 6. I'm successful at submitting it using a link as follows:
<form method="POST" action="<%= url_for :action => :create %>" id="new_form"> ... </form>
<a href="javascript:;" onclick="$('#new_form').submit();">Submit form</a>
However, this clears the page as my create action has no ERB template. I have tried to add:
render :layout => false, :use_layout_on_ajax => false
in my create action. However, it does not help.
I'm trying to emulate the RubyOnRails "remote: true" option on a form tag.
|
|
|
Post by Vladimir Musulainen on Jul 25, 2018 7:45:57 GMT
It depends on which behaviour you want to get after submitting form. If you want the app goes to another page add redirect like
def create # some code here redirect :action => :index end
|
|
|
Post by fnllc on Jul 25, 2018 9:30:17 GMT
I want the app to stay on the page with the form. No change after clicking the link.
|
|
|
Post by Vladimir Musulainen on Jul 25, 2018 9:52:28 GMT
in this case is better the following approach:
<form> ... <button id="submit">Submit</button> </form>
<script>
$("submit").on('click', function(){ //collect entered data var enteredData = {} //use ajax to make POST request to controller action $.post('path_to_controller_action', enteredData) })
</script>
|
|