简体   繁体   中英

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:

<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. 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. To be honest, I am pretty inexperienced with Jquery and PHP and am not sure where to go from here. 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. 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:

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

See also https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Hey you could try something like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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