簡體   English   中英

將用戶從XML響應重定向到外部站點

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

我正在使用jquery來獲取一個php文件,該php文件向外部站點發出php curl請求,並帶有付款請求的信息,該外部站點返回如下XML:

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

發出請求后,我想找到URI並使用Jquery將客戶重定向到該URI。 我能夠找到URI並以文本形式或作為警報將其返回,但是無法確定如何重定向頁面。 老實說,我對Jquery和PHP經驗不足,並且不確定從何而來。 我基本上已經嘗試過window.location,但無法正常工作,我不確定從這里去哪里。 有沒有人有什么建議?

<!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>

在按鈕單擊功能的末尾添加它。

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

希望這可以幫助。

您只需要將URL分配給window.location例如:

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

另請參閱https://developer.mozilla.org/zh-CN/docs/Web/API/Window/location

嘿,你可以嘗試這樣的事情

<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