问题描述
我将cord2与cordova一起用于android应用.在此,我正在使用支付网关,因此,我需要在不打开浏览器的情况下将表单值发布到外部支付URL.
I am using angular2 with cordova for android app. In this I'm using payment gateway so, to do this I need to post form values to external payment URL without opening browser.
示例代码为:
<form action="<External URL>" method="POST">
<input type="text" value="paymentID">
</form>
请帮助我.
推荐答案
要使表单提交无法在浏览器中打开,您必须允许导航到该URL.您可以通过在config.xml中添加allow-navigation
条目(例如<allow-navigation href="http://example.com/*" />
)来实现.
To make the form submit not open in browser you have to allow navigation to that url.You can do it by adding an allow-navigation
entry in your config.xml like this <allow-navigation href="http://example.com/*" />
.
在Android中,您还需要安装cordova-plugin-whitelist
In Android you will also need to install cordova-plugin-whitelist
但是您不应真正将表单提交到外部URL,而应使用XHR(AJAX)将POST发送到服务器,而不是将表单提交给服务器.
But you should not really do a form submit to an external url, you should use XHR (AJAX) to send the POST to the server instead of the form submit.
这篇关于如何防止在Cordova的浏览器中打开外部链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!