通过AJAX动态发送POST表单数据JSON格式与jQuery

编程入门 行业动态 更新时间:2024-10-09 11:26:37
本文介绍了通过AJAX动态发送POST表单数据JSON格式与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我徜徉在JSON格式通过AJAX使用jQuery动态如何发送POST表单数据? 例如,我编码JQ是这样的:

I wander how send post form data in json format via ajax with JQuery dynamically? For example I'm coding something like this in JQ:

$.post("test.php", { func: "getNameAndTime" }, function(data){ alert(data.name); // John console.log(data.time); // 2pm }, "json");

这很好,但在现场的应用程序经常需要发送大量表单数据和用户可以动态改变的领域,所以我不知道有多少FUNC1,FUNC2,FUNC3甚至FUNC []将被发送。 在Q是如何动态地做到这一点,在旧世界的AJAX我可以做它通过serealizing的形式发送到服务器。 感谢名单提前。

and that's good, but in live apps often need to send huge form data and user can dynamically change the fields, so I don't know how many func1, func2, func3 or even func[] will be sent. The q is how to do this dynamically, in old world of an AJAX I could done it by serealizing the form and send to the server. Thanx in advance.

推荐答案

是的,我可以把所有的数据到服务器,并在任何情况下,它会运行良好, 例如:

Yes I can send all the data to the server and in any case it will worked well, example:

$(function() { // on document load $('#email_form').submit(function() { // set onsubmit event to the form var data = $('#email_form').serialize(); // serialize all the data in the form $.ajax({ url: 'testJson.php', // php script to retern json encoded string data: data, // serialized data to send on server dataType:'json', // set recieving type - JSON in case of a question type:'POST', // set sending HTTP Request type async:false, success: function(data) { // callback method for further manipulations for (key in data.email) { alert(data.email[key]); } }, error: function(data) { // if error occured } }); return false; });

});

更多推荐

通过AJAX动态发送POST表单数据JSON格式与jQuery

本文发布于:2023-06-06 10:50:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/539034.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   格式   动态   数据   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!