jQuery将序列化的表单输入转换为xml字符串 [英] jquery convert serialized form inputs to xml string

查看:205
本文介绍了jQuery将序列化的表单输入转换为xml字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取所有表单输入,然后用它们创建一个包含有值的xml字符串,以便通过ajax发送它们.

I'm trying to get all my form inputs and then create with them an xml string containing there values in order to send them via ajax.

我想要这个:

<form id="formtest">
 <input type="text" name="test1" id="test1"/>
 <input type="text" name="test2" id="test2"/>
 <input type="text" name="test3" id="test3"/>
 <input type="text" name="test4" id="test4"/>
 <input type="text" name="test5" id="test5"/>           
</form>

成为:

<formtest>
  <test1></test1>
  <test2></test2>
  <test3></test3>
  <test4></test4>
  <test5></test5>
</formtest>

这怎么办?

感谢提前.

推荐答案

首先,在jQuery中创建XML文档:

First, create your XML document within jQuery:

var xml = $('<xmlBody></xmlBody>'); //<xmlBody> can be replaced with whatever tag is appropriate for your uses

添加类似这样的值:

xml.find('xmlBody').first().append('<tag>'+data+'</tag>');

您可能需要一个插件来序列化XML. ,也许?

You may need a plugin to serialize the XML. This, perhaps?

这是一个非常简单的示例,但希望它可以帮助您入门.环顾 jQuery文档以获得更多信息.

This is a very simple example, but hopefully it will get you started. Look around the jQuery docs for more info.

这篇关于jQuery将序列化的表单输入转换为xml字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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