Alagu Madhu       :

I am facing a problem in login screen using XMLHttpRequst sending the
data to the controller.controller is getting the value through
request.POST. but its not redirecting the same.

    if result[0]:
        return HttpResponseRedirect("/main/")
    else:
        return HttpResponseRedirect("/login/")



HttpResponseRedirect is working fine with html but with XMLHttpRequest
is not working. Please help us in this regard.

If you point your XMLHttpRequest object to this login view only the XMLHttpRequest object gets redirected not the whole page.

That's a feature, not a bug. :) When you create a XMLHttpResponse object it's like you create another virtual instance of your browser and you redirect that.

If you want to redirect the whole page based on the response of the XMLHttpRequest you need to do something like this in JavaScript and change your view.

Your view should return something.

        if result[0]:
                return HttpResponse('main')
        else:
                return HttpResponse('login')

And then parse that in the onreadystatechange function in your JavaScript.

xmlhttpreq.onreadystatechange=function() {
        if (xmlhttpreq.readyState==4) {
                if (xmlhttpreq.responseText=='main') {  
                        // redirect to /main/
                        document.location.href='/main/';
                } else {
                        // tell the user - there where errors.
                }
        }
}


--
Glisha
The perfect OS, MS-DOS!
No patches, no root exploits for 21 years.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to