0

When my member registration form correctly filled in and submitted, server responds with redirect link. But my ajax does not redirect the website. I do not receive any errors, where is my mistake?

<script type="text/javascript">
 $(document).ready(function() { 
  $("[name='submit']").click(function() { 
   $.ajax({
    type: "POST",
    data: $(".form-signup").serialize(),
    url: "http://www.refinethetaste.com/FLPM/content/myaccount/signup.cs.asp?Process=Add2Member", 
    success: function(output) { 
    if (output.Redirect) {
      window.location.href = output.Redirect;
    }
    else {
     $('.sysMsg').html(output);
     }
    },
    error: function(output) {
    $('.sysMsg').html(output);
    }
   }); 
    }); 
 }); 
 </script> 

asp codes:

If Session("LastVisitedURL") <> "" Then
Response.Redirect Session("LastVisitedURL")
Else
Response.Redirect "?Section=myaccount&SubSection=myaccount"
End If
zurna
  • 1,161
  • 4
  • 16
  • 20
  • Why don't you try debugging your code? It looks like a simple `alert(output.Redirect);` in the first line of success handler will help you a lot: no alert means no success, empty alert means nothing returned, alert with the correct url means some problem in `window.location.href = output.Redirect;`. – Li0liQ Mar 14 '10 at 23:43
  • I am sorry I misexplained it. Page website supposed to be redirected is loaded into .sysMsg div. – zurna Mar 14 '10 at 23:45
  • Read this question: http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call/1534662#1534662 - there are general issues with redirect responses to ajax requests. The answers provide some good background to the problem. – Steg Mar 14 '10 at 23:46
  • I read the other question. Chosen answer there will not do it for me. Is there a way to check if output contains link in it? Something like if (output.http) ? – zurna Mar 14 '10 at 23:58

2 Answers2

0

Just try this:

if (output.Redirect) {
      alert(output.Redirect);
      window.location.href = output.Redirect; 
    } 

to check what comes back from the server.

Michael Ulmann
  • 1,077
  • 5
  • 16
0

You need to use some sort of debugger (firebug in firefox or web inspector in webkit) and stop the program at:

if (output.Redirect) {

in the success callback and at

$('.sysMsg').html(output);

in the error callback.

Then you can examine the contents and see what is in them. Without knowing what is in the object being returned (if there even is one) then no one can debug it.

Everyone needs to stop using alert and writing to a part of the page as error debugging and work straight in a debugger. Otherwise, your output also gets parsed by what is parsing it. You never know if the error is in the output or in the thing that tried to print it to the string.

I advise using both debuggers as both work differently and have their own strengths and weaknesses.

davehamptonusa
  • 109
  • 1
  • 5