07-01-2011 01:21, Timuçin Kızılay yazmış:


I have a code like this in one of my controller code:
-----------
@expose('json')
@require(predicates.has_permission(u'something', msg=u'You do not have
permission!'))
def somejsonhandler(self, **kw):
somevalue = u'something'
someint = 123
return dict(somevalue=somevalue, someint=someint)
----------

This is called by an ajax code from the browser.
I can not catch the error, that code always returns status code 200.

I'm using jquery library for ajax.
The error handler code like this:
function AJAX_error(xhr, textStatus, errorThrown){
alert('Message from Server: ' + xhr.status + '\n:\n' + errorThrown +
'\n:\n' + textStatus);
};

this javascript is called and I see that status is 200 and it's actually
sending me the login page and it errors because ajax function was
waiting for a json response.

can you point me some hints to "how can I get 403 status code or
something other than 200 ?"

I'd like to update about this post:

When the user logged in, I can get 403 status code from javasript. But when user is not logged in, controller tries to redirect to login page and I get status code 200 and login page from ajax.

So, this redirect thing is only for 401 response. How can I disable redirect for some controller methods that are called by ajax?

What I want to do is:
some controller methods are web pages so redirect to login page, and others are called by javascript ajax functions so they should not redirect to login page, they should return 401 or 403 responses so that I can catch the erron on javascript side.

--
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en.

Reply via email to