Jump to content
Sign in to follow this  
helloworld001

Quick help with redirecting with javascript/ajax

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?

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.