我将如何使用jQuery ajaxify一种形式?我将、如何使用、形式、jQuery

2023-09-10 16:13:37 作者:兔尾映樱.

我想不使用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).