我正在使用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");
}
});
});
您必须先解码 json 对象,然后获取 url。
<?php
$json = '{"orderId":"308fea18-9288-460e-8c24-e2******","formUrl":"https://test.bank.com/payment/merchants/payment.html?mdOrder=308fea18-e2c68d9d3a2e&language=en"}';
$json_decoded = json_decode($json); //Decode the json object
$url = $json_decoded->formUrl; //Get the url
header("Location: $url"); //Pass the url into redirection