我将如何使用jQuery ajaxify一种形式? [英] How would I use jQuery to ajaxify a form?

查看:289
本文介绍了我将如何使用jQuery ajaxify一种形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不使用jQuery插件AJAXIFY一种形式。什么是流程使这种情况发生。我有我的形式。我应该怎么设置动作?我应该标题脚本是什么?请记住,我不希望使用任何插件。我只是需要一个基本算法使用jQuery ajaxifying形式。

I'm trying to AJAXIFY a form without using jQuery plugins. What is the process for making this happen. I have my form. What should I set the action to? What should the header script be? Keep in mind that I do not want to use any plugins. I just need a basic algorithm for ajaxifying forms using jquery.

推荐答案

的动作应不管它如果你不使用JavaScript 会。

注:以下所有链接去jQuery的文档的相关章节)

然后你会绑定功能的提交 事件序列表单数据,并使用了作出的 Ajax请求(大概从action属性)。它必须 prevent的默认操作以提交事件。

Then you would bind a function to the submit event that serialized the form data and used that to make an Ajax request (probably reading the URI from the action attribute). It would have to prevent the default action for submit events.

我相信jQuery的设置的X请求,通过HTTP头。所以,你只需要修改服务器端程序返回不同的数据,如果这是present(用正确的价值)。这可能是简单,只是切换到不同的视图(如果你使用的是MVC模式)。

I believe jQuery sets an X-Requested-With HTTP header. So you just need to modify your server side process to return different data if that is present (with the right value). This could be as simple as just switching to a different view (if you are using a MVC pattern).

这篇关于我将如何使用jQuery ajaxify一种形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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