【发布时间】:2019-01-11 09:23:54
【问题描述】:
我正在使用 php 发出 GET 请求。响应后,它必须将我重定向到响应 URL,但我不知道该怎么做。响应为json格式,如下:
{"orderId":"308fea18-9288-460e-8c24-e2******","formUrl":"https://test.bank.com/payment/merchants/payment.html?mdOrder=308fea18-e2c68d9d3a2e&language=en"}
此响应是在付款请求成功后将我重定向到包含卡信息的页面。
这是表单请求:
<form name="PaymentForm" action="https://test.bank.com/payment/register.do" method="GET" id="formPayment">
<input type="hidden" name="userName" id="userName" value="api">
<input type="hidden" name="password" id="password" value="api2">
<input type="hidden" name="orderNumber" id="orderNumber" value="00000116">
<input type="hidden" name="amount" id="amount" value="1000">
<input type="hidden" name="description" id="description" value="description">
<input type="hidden" name="language" id="language" value="en">
<input type="hidden" name="pageView" id="pageView" value="DESKTOP">
<input type="hidden" name="clientId" id="clientId" value="2">
//a button for payment confirmation
<input value="Изпрати" type="submit" id="buttonPayment" class="btn btn-lg btn-primary">
</form>
请求成功后如何自动重定向用户?
我搜索了许多链接,但不知何故无法解决我的问题。
现在我尝试使用 ajax 发送数据,但我发现了其他错误:
Access to XMLHttpRequest at 'https://test.bank.com/payment/register.do?[object%20FormData]' from origin 'http://site.domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这是一个ajax:
$( "#buttonPayment" ).click(function() {
var modal = $(this);
$.ajax({
url: "https://ecomtest.dskbank.bg/payment/rest/register.do",
crossDomain: true,
method: "GET",
data: new FormData($('#formPayment')[0]), // The form with the file inputs.
processData: false, // Using FormData, no need to process data.
contentType: false, // Using FormData, no need to process data.
success: function (data) {
console.log(data)
},
error: function () {
console.log("error");
}
});
});
【问题讨论】:
-
关键字是Ajax。您在用户浏览器中通过 JavaScript 发出请求。然后你检查它的返回值并做其他事情。 (例如,如果支付成功,将用户重定向到新页面)
-
我必须使用 Ajax 发送参数并成功尝试捕获响应?