无需通过AJAX刷新页面提交表单 [英] Submit form without reloading page through AJAX

查看:135
本文介绍了无需通过AJAX刷新页面提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法的形式提交到服务器,无需重新加载页面的Ajax响应。我能够做到这一点与提交按钮。但是,我怎么能做到这一点点击一个链接时。

Is there any way to submit the form to server for an AJAX response without reloading the page. I am able to do this with submit button. But how can I do that when a link is clicked.

我来了解一个JavaScript的方法来做到这一点,

I came to know about a javascript method to do this,

var form = document.getElementById('myForm');
form.submit();

但上面的code重新加载页面。我才知道,我们可以使用jQuery做,但怎么样?

But the above code reloads the page. I came to know that we can do this with jquery but how?

请注意,我正在开发on Rails的3.0.4我的Ruby应用程序,我使用的轨道AJAX是这样的。

Please Note that I am developing my application in Ruby on Rails 3.0.4 and I am using the rails AJAX like this.

<%= form_for @search, :remote => true, :url => request_path, :html => {:method => :get, :id => :my_form} do |f| %>

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

我得到它的工作,只需使用该code。无需定义一个函数内提交。

I got it working by just using this code. No need to define a function inside submit.

$('#myform').submit();

这篇关于无需通过AJAX刷新页面提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆