提交表单返回 XML,如何使用该信息
我正在使用 API 来收集一些信息。我使用 POST 将表单发送到 API 的 URL。 并且它返回 XML。
基本上,
<form action="http://api.paythrudev.com/gettoken" method="POST">
<input type="text" name="api_key" value="xxxx"/>
<input type="text" name="api_password" value="xxxx"/>
<input type="text" name="item_name" value="AA"/>
<input type="text" name="item_price" value="12"/>
<p><input type="submit" /></p>
</form>
当我提交此表单时,它会显示 XML。
但是,
当用户单击“提交”按钮时,我不希望用户看到 XML,但我希望将用户重定向到页面(返回的 XML 将 URL 作为元素)
我怎样才能实现这一点?
- 通过jquery的post方法?
- 我可以通过 PHP 实现这个功能吗?不使用 JavaScript。
提前致谢。
I am using an API to collect some information. I send a form using POST to the API's URL.
And it returns XML.
Basically,
<form action="http://api.paythrudev.com/gettoken" method="POST">
<input type="text" name="api_key" value="xxxx"/>
<input type="text" name="api_password" value="xxxx"/>
<input type="text" name="item_name" value="AA"/>
<input type="text" name="item_price" value="12"/>
<p><input type="submit" /></p>
</form>
When i submit this form, it displays XML.
However,
When user clicks submit button, i dont want the user to see the XML but I want the user to be redirected to a page (returning XML has the URL as an element)
How can i achieve this?
- By jquery's post method?
- Can i achieve this by PHP? without using javascript.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PHP 将是解析 xml 的最佳选择。我对您的主要问题是您发布的页面是否驻留在您自己的服务器上,或者您是否实际上将您的用户完全带到了不同的网站(我怀疑您正在做后者)。
我建议您将页面发布到自身,然后在验证已提交的数据后,在 php 中创建一个 http post,将必要的变量发送到目标 url。您应该能够以这种方式在 php 文件中接收 xml,并且由于您仍然在自己的域中操作,因此您可以选择在接收数据后要执行的操作。
归根结底,您似乎正在发布到一个应该用作网络服务的页面。您需要从 php 文件访问 Web 服务并解析那里的数据,而不是这样做。
解析xml的示例: http://www.php.net/manual/ en/example.xml-struct.php
找不到通过 php 使用 Web 服务的好教程,但我建议搜索“consume web service xml php”
最好的问候
PHP would be your best bet for parsing xml. My main question to you would be whether or not the page that you are posting to resides on your own server or whether or not you are actually bringing your user to a different site altogether (my suspicion is that you are doing the latter).
I would recommend that you have the page post to itself, and then after validating the data that has been submitted then create a http post within the php that sends the necessary variables to the target url. You should be able to receive xml within your php file that way, and since you are still operating in your own domain you can then choose what you want to happen upon receiving the data.
What it boils down to is that it looks like you're posting to a page that should be used as a web service. Instead of doing that, you need to access the web service from your php file and parse the data there.
Example of parsing xml: http://www.php.net/manual/en/example.xml-structure.php
Can't find a good tutorial for consuming a web service via php, but I would recommend searching around for "consume web service xml php"
Best regards