如何使用JQuery获取HTML表单数据并写入XML? [英] How to take HTML form data and write to XML using JQuery?

查看:395
本文介绍了如何使用JQuery获取HTML表单数据并写入XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的表单:

 < form method =postid =aodform> ; 
< label for =a>动物:< / label>
< input class =inputtype =textname =a/>
< label for =s>香肠:< / label>
< input class =inputtype =textname =s/>
< label for =g> Bird:< / label>
< input class =inputtype =textname =g/>
< label for =d>甜品:< / label>
< input class =inputtype =textname =d/>
< input id =submittertype =submit/>
< / form>

我需要在表单中输入值并覆盖(替换)相应节点的文本值一个现存的XML文件如下所示:

 < aod> 
< animal> x< / animal>
<香肠> x< /香肠>
< bird> x< / bird>
<甜点> x< /甜点>
< / aod>

现在,我知道我可以使用

  $( #aodform)提交(); 

在Jquery中实现一个表单提交,但在此之后我迷路了!我试图找出如何获取这些表单值,将它们作为变量存储在函数中,然后写入XML文件(全部在Jquery中)。



I已经在谷歌搜索框中找到了相似的主题,但不太相似,足以帮助我解决问题。有人请帮助我吗?谢谢!

我不能使用任何服务器端语言,比如PHP,否则我会这样。 解决方案

您无法使用由于安全考虑,使用javascript / jquery创建或编辑本地XML文件。想象一下,去一个网站,网站管理员编写了一些代码,知道是什么,然后把它放在你计算机上的一个文件中。

写入本地使用JavaScript的文件是使用Cookie或HTML5 localStorage



localStorage可让您存储数组的字符串键值和/或属性名称和值。



如果您需要XML文件,您必须调用服务器端脚本,该脚本有权在服务器上编写文件,然后您可以通过它的url访问该文件。


I have a form that looks like this:

<form method="post" id="aodform">
<label for="a">Animal:</label>
<input class="input" type="text" name="a"/>
<label for="s">Sausage:</label>
<input class="input" type="text" name="s"/>
<label for="g">Bird:</label>
<input class="input" type="text" name="g"/>
<label for="d">Dessert:</label>
<input class="input" type="text" name="d"/>
<input id="submitter" type="submit"/>
</form>

I need to take the entered values in the form and overwrite (replace) the corresponding node's text value in an EXISTING XML file that looks like this:

<aod>
<animal>x</animal>
<sausage>x</sausage>
<bird>x</bird>
<dessert>x</dessert>
</aod>

Now, I know I can use

$("#aodform").submit();

to achieve a form submit in Jquery, but after this I'm lost! I'm trying to figure out how to get those form values, store them as variables in a function that then writes to the XML file (all in Jquery).

I've searched all over the google box and found similar subjects, but not quite similar enough to help my situation. Would someone please help me? Thank you!

P.S. I CAN NOT use any server-side language, like PHP, or else I would.

解决方案

You won't be able to create or edit a local XML file using javascript/jquery because of security concerns. Imagine going to a website and the webmaster wrote some code doing who knows what and puts this in a file on your computer...

The only way to write to a local file using javascript is to use cookies or HTML5 localStorage.

localStorage will allow you to store string keys and values of arrays and/or property names and values of objects.

If you need an XML file you will have to call a server-side script that has permission to write the file on the server, which you can then access via it's url.

这篇关于如何使用JQuery获取HTML表单数据并写入XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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