Jump to content

Quick help with redirecting with javascript/ajax


helloworld001

Recommended Posts

I would like to know how can I redirect a jquery dialog function to a different page, if another function is true? 

 

For eg. 

 

1. User 1 sends a request to User 2.

2. User 2 accepts the request. 

3. User 1 still has the request "dialog" window open.  Instead, I would like to have that dialog window close and redirect to a specified page. Of course this only happens after User 2 accepts the request and I check against it in the database.

 

Here is the function for when User 1 makes a request.

		<script>
		$(function() {
			$("#new-dialog").dialog({
				resizable: true,
				autoOpen: false,
				modal: true,
				width: 600,
				height: 300,
				buttons: {
					"Cancel Trade": function(e) {
						$(this).dialog("close");
						
						$.ajax({
							type:"post",
							url:"request-trade?by=<?php echo $session_requestById; ?>&to=<?php echo $session_requestToId; ?>",
							data:"action=cancelTrade",
							success:function(data){
								if(data == true) {
									alert('success');
								} else {
									alert('not deleted');
								}
									//window.location.href='trade?by=<?php echo $session_requestById; ?>&to=<?php echo $session_requestToId; ?>';
								
							}
						});
					}
				}
			});
			
			
			$(".dialogify").on("click", function(e) {
				e.preventDefault();
				$("#new-dialog").html("");
				$("#new-dialog").dialog("option", "title", "Loading...").dialog("open");
				$("#new-dialog").load(this.href, function() {
					$(this).dialog("option", "title", $(this).find("h1").text());
					$(this).find("h1").remove();
				});
			});
		});
		</script>

And here is the new function in which I  check the database for match.  If it returns true, I would like to redirect the above dialog/page. 

		<script>
			$('document').ready(function(){
				function checkTrade() {
							
					$.ajax({
						type:"post",
						url:"request-trade?by=<?php echo $session_requestById; ?>&to=<?php echo $session_requestToId; ?>",
						data:"action=checkTrade",
						success:function(data){
							window.location.href='trade?by=<?php echo $session_requestById; ?>&to=<?php echo $session_requestToId; ?>';
							
						}
					});
				}	
				
			});
		
		</script>

So what am I missing to do the redirect?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.