我正在使用Ionic应用程序来构建一个Android应用程序。
我有一个隐藏元素的html表单,我通过javascript提交(通过模拟隐藏的提交按钮点击)。
这会重定向到付款网关页面。
这是我需要实现的目标: 保持HTML表单不变,我需要在Ionic应用程序内浏览器中打开表单操作中指定的URL。
我有两个限制:
以下是代码:
HTML表单:
<form action='https://secure.payu.in/_payment' method="POST">
<input type="hidden" name="firstname" id="payu_data.firstname" ng-model="payu_data.firstname"/>
<input type="hidden" name="surl" id="payu_data.surl" ng-model="payu_data.surl">
<input type="hidden" name="furl" id="payu_data.furl" ng-model="payu_data.furl">
<input type="hidden" name="phone" id="payu_data.phone" ng-model="payu_data.phone"/>
<input type="hidden" name="key" id="payu_data.key" ng-model="payu_data.key"/>
<input type="hidden" name="hash" id="payu_data.hash" ng-model="payu_data.hash"/>
<input type="hidden" name="service_provider" id="payu_data.service_provider" ng-model="payu_data.service_provider"/>
<input type="hidden" name="txnid" id="payu_data.txnid" ng-model="payu_data.txnid"/>
<input type="hidden" name="productinfo" id="payu_data.productinfo" ng-model="payu_data.productinfo"/>
<input type="hidden" name="amount" id="payu_data.amount" ng-model="payu_data.amount"/>
<input type="hidden" name="email" id="payu_data.email" ng-model="payu_data.email"/>
<!--<input type="hidden" name="udf1" id="payu_data.udf1" value="buy_subscription" />-->
<input type= "submit" value="submit" id="id_payu_submit_button" hidden>
</form>
使用Javascript:
// submit payu form
document.getElementById("id_payu_submit_button").click();
// initiate websocket
var socket = DOMAIN.socket + API_URLS.billingInitiationSocket;
var connection = new WebSocket(socket);
// When the connection is open, send some data to the server
connection.onopen = function () {
// Send the message 'Ping' to the server
connection.send(userService.userSession.user_data.token);
};
// Log errors
connection.onerror = function (error) {
console.log("Error in initiating billing socket: " + error);
};
// Log messages from the server
connection.onmessage = function (e) {
console.log('Server: ' + e.data);
var data = JSON.parse(e.data);
console.log("Websocket received data: " + JSON.stringify(data));
if (data.hasOwnProperty("redirect") && data.redirect===true){
$state.go("app.home");
alert("Something happened!");
}
};