【问题标题】:How to post HTML-form data as XML via POST to an URL and get the XML response back如何通过 POST 将 HTML 表单数据作为 XML 发布到 URL 并返回 XML 响应
【发布时间】:2015-05-04 10:24:04
【问题描述】:

我想将用户表单输入作为 XML 发布到 URL 并返回结果以显示给用户。

HTML 部分:

<form id="postXmlForm" method="post">
<table>
    <tr>
        <td>Userinput1:</td>
        <td><input type="number" id="userInput1" name="userInput1"></td>
    </tr>
    <tr>
    <tr>
        <td>Userinput2:</td>
        <td><input type="text" id="userInput2" name="userInput2"></td>
    </tr>
    <tr>
        <td colspan="2"><input type="Button" value="Send"></td>
    </tr>               
</table>
</form>

我应该发布到 URL 的内容:

<Request><input1>123456</input1>
<input2>textinoput</input2></Request>

我不确定,最好的方法是将用户输入包装成一个字符串并将其作为 XML 发布到给定的 URL 并显示答案 (XML)... jQuery? php?

【问题讨论】:

  • 使用 PHP SimpleXML Parser 完成此任务

标签: php jquery xml post


【解决方案1】:

我不确定为什么要将数据作为 XML 传递到目标页面,而通过 post 方法传递变量既简单又安全,但作为响应,您可以回显包括 XML 在内的任何格式。但如果你想传回参数组,我的建议是 JSON。

JQuery 有 getJSON 可以轻松帮你解析 JSON。

【讨论】:

  • 这很简单 ;) ...因为我必须这样做。服务需要该格式的 XML 并返回 XML。
猜你喜欢
  • 2011-01-10
  • 1970-01-01
  • 2011-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-03
  • 2011-12-27
  • 2017-09-27
相关资源
最近更新 更多