简体   繁体   English

将用户从XML响应重定向到外部站点

[英]Redirecting a user to external site from XML response

I am using jquery to get a php file, the php file makes a php curl request to an external site with information for a payment request, the external site returns XML which looks like this: 我正在使用jquery来获取一个php文件,该php文件向外部站点发出php curl请求,并带有付款请求的信息,该外部站点返回如下XML:

<Request valid="1">
<URI>www.dynamicpaymentpage.com/URI>
</Request>

After making the request I want to find the URI and redirect the customer to that URI with Jquery. 发出请求后,我想找到URI并使用Jquery将客户重定向到该URI。 I'm able to find the URI and return it in text or as an alert, but can't work out how to redirect the page. 我能够找到URI并以文本形式或作为警报将其返回,但是无法确定如何重定向页面。 To be honest, I am pretty inexperienced with Jquery and PHP and am not sure where to go from here. 老实说,我对Jquery和PHP经验不足,并且不确定从何而来。 I've basically tried window.location and haven't been able to get that working and I'm not sure where to go from here. 我基本上已经尝试过window.location,但无法正常工作,我不确定从这里去哪里。 Does anyone have any suggestions? 有没有人有什么建议?

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.ajax({
type: "GET",      
url: "deets.php", 
success: function(result){
xmlDoc = $.parseXML(result),
  $xml = $( xmlDoc ),
  $URI = $xml.find( "URI" );
///this is just to make sure I've found the right bit of XML /// $( "#div1" ).append( $URI.text() );

        }});
    });
});

</script>
</head>
<body>

<div id="div1"></div>

<button>Go!</button>

</body>
</html>

Add this at the end of your button click function. 在按钮单击功能的末尾添加它。

window.location.href = "your-url";

Hope this helps. 希望这可以帮助。

You just need to assign the URL to window.location like: 您只需要将URL分配给window.location例如:

window.location.href = $xml.find("URI").text();

See also https://developer.mozilla.org/en-US/docs/Web/API/Window/location 另请参阅https://developer.mozilla.org/zh-CN/docs/Web/API/Window/location

Hey you could try something like this 嘿,你可以尝试这样的事情

<page view-id="/view.xhtml">
  <action execute="#{facesContext.externalContext.redirect('http://')}" />
</page>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM