Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当客户端位于另一个域上时,如何获取form.submit响应?_Javascript_Php_Wordpress_Post - Fatal编程技术网

Javascript 当客户端位于另一个域上时,如何获取form.submit响应?

Javascript 当客户端位于另一个域上时,如何获取form.submit响应?,javascript,php,wordpress,post,Javascript,Php,Wordpress,Post,我已经使用javascript创建了一个表单,它的作用是,它将客户带到另一个域,其中包含一些数据,问题是当客户在另一个域上时,他批准了某个内容,另一个域向我发送了一个回调,但我无法接收它,因为form.submit是单向的 我到处找了找,但找不到任何解决办法 <script> var theAlifForm, newInput1, newInput1,newInput2,newInput3,newInput4,newInput5,newInput6,newInput7; //

我已经使用javascript创建了一个表单,它的作用是,它将客户带到另一个域,其中包含一些数据,问题是当客户在另一个域上时,他批准了某个内容,另一个域向我发送了一个回调,但我无法接收它,因为form.submit是单向的

我到处找了找,但找不到任何解决办法

 <script>
 var theAlifForm, newInput1, newInput1,newInput2,newInput3,newInput4,newInput5,newInput6,newInput7;
  // Start by creating a <form>
  theAlifForm = document.createElement('form');
  theAlifForm.action = 'https://alifpay.tj/web';
  theAlifForm.method = 'post';
  // Next create the <input>s in the form and give them names and values
  newInput1 = document.createElement('input');
  newInput1.type = 'hidden';
  newInput1.name = 'token';
  newInput1.id = 'token';
  newInput1.value = "<?php echo  $token;?>";

  newInput2 = document.createElement('input');
  newInput2.type = 'hidden';
  newInput2.name = 'key';
  newInput2.id = 'key';
  newInput2.value = "<?php echo  $a->key;?>";

   newInput3 = document.createElement('input');
  newInput3.type = 'hidden';
  newInput3.name = 'callbackUrl';
  newInput3.id = 'callbackUrl';
  newInput3.value = "<?php echo $a->callbackUrl;?>";

   newInput4 = document.createElement('input');
  newInput4.type = 'hidden';
  newInput4.name = 'returnUrl';
  newInput4.id = 'returnUrl';
  newInput4.value = "<?php echo $a->returnUrl;?>";

    newInput5 = document.createElement('input');
  newInput5.type = 'hidden';
  newInput5.name = 'amount';
  newInput5.id = 'amount';
  newInput5.value = "<?php echo $a->amount;?>";

  newInput6 = document.createElement('input');
  newInput6.type = 'hidden';
  newInput6.name = 'orderId';
  newInput6.id = 'orderId';
  newInput6.value = "<?php echo $a->orderid;?>";

    newInput7 = document.createElement('input');
  newInput7.type = 'hidden';
  newInput7.name = 'info';
  newInput7.id = 'info';
  newInput7.value = "<?php echo $a->info;?>";

  // Now put everything together...
  theAlifForm.appendChild(newInput1);
  theAlifForm.appendChild(newInput2);
  theAlifForm.appendChild(newInput3);
  theAlifForm.appendChild(newInput4);
  theAlifForm.appendChild(newInput5);
  theAlifForm.appendChild(newInput6);
  theAlifForm.appendChild(newInput7);
  console.log(theAlifForm);
document.getElementById('hidden_form_container_custom').appendChild(theAlifForm);
  theAlifForm.submit();

  </script>

变量theAlifForm、newInput1、newInput1、newInput2、newInput3、newInput4、newInput5、newInput6、newInput7;
//首先创建一个
theAlifForm=document.createElement('form');
动作https://alifpay.tj/web';
theAlifForm.method='post';
//接下来,在表单中创建s,并给它们命名和值
newInput1=document.createElement('input');
newInput1.type='隐藏';
newInput1.name='token';
newInput1.id='token';
newInput1.value=“”;
newInput2=document.createElement('input');
newInput2.type='隐藏';
newInput2.name='key';
newInput2.id='key';
newInput2.value=“”;
newInput3=document.createElement('input');
newInput3.type='隐藏';
newInput3.name='callbackUrl';
newInput3.id='callbackUrl';
newInput3.value=“”;
newInput4=document.createElement('input');
newInput4.type='隐藏';
newInput4.name='returnUrl';
newInput4.id='returnUrl';
newInput4.value=“”;
newInput5=document.createElement('input');
newInput5.type='隐藏';
newInput5.name='amount';
newInput5.id='金额';
newInput5.value=“”;
newInput6=document.createElement('input');
newInput6.type='隐藏';
newInput6.name='orderId';
newInput6.id='orderId';
newInput6.value=“”;
newInput7=document.createElement('input');
newInput7.type='隐藏';
newInput7.name='info';
newInput7.id='info';
newInput7.value=“”;
//现在把一切都放在一起。。。
theAlifForm.appendChild(newInput1);
theAlifForm.appendChild(newInput2);
theAlifForm.appendChild(newInput3);
appendChild(newInput4);
appendChild(newInput5);
附加子项(新输入6);
附加子项(新输入7);
控制台日志(theAlifForm);
document.getElementById('hidden_form_container_custom').appendChild(theAlifForm);
theAlifForm.submit();

那么,既然客户此时在另一个域上,我如何接收回调呢?提前感谢。

您正在向他们发送
$a->callbackUrl
,这是alifpay在客户批准付款后将重定向到的URL。“接收回调”意味着您需要相应地设置端点;像
https://yourdomain/afterpayment
。在wordpress仪表板中创建页面,然后在functions.php中的函数中处理POST数据,该函数检查页面是否为
afterpayment
,并从那里继续。感谢您的回复,问题是他们在客户付款后重定向到返回url,但他们在$a->callbackUrl上报告付款状态;我需要在那里处理它,这样就不会加载任何页面,因为当他们报告时,客户仍然在他们的网页上;URL是
https://yourdomain/wp-admin/admin-ajax.php
。他们发送到那里的POST数据必须包含
操作
;不确定这是否得到支持?回复他们的发帖请求是否重要?如果没有,您仍然可以执行我描述的操作,您将以任何方式获得POST数据。你发回一个页面并不重要,因为他们很可能会放弃回复。我不需要再发回任何东西,问题是我必须根据付款状态更新我的系统。你能检查一下他们发给我的这个例子吗?这会让事情变得更清楚。对,那么你到底被困在哪里?只需将
thank_you.php
放入wordpress文件夹,并将URL作为回调URL提供给他们即可。上面写着
echo“Success”
你只需按照他们的评论做即可:
//更新成功付款的日期
我很乐意帮助你,但我不知道你不了解哪一部分。