tags:

views:

34

answers:

2

Hi. I have a AJAX post method that gets xml data from server. But when user session is over server will response with login page. And in that case I can't detect if response in not xml because $.post don't call callback function.

How can I detect if response is not xml ?

Thanks!

A: 

Try to skip specifying dataType in $.post(), then you should get any kind of data and validate yourself if its XML or something else...

Laimoncijus
+1  A: 

instead of using $.post, use $.ajax and set type: 'POST'.

You can then do callbacks on all sorts of events, see http://api.jquery.com/jQuery.ajax/ for all details. Your calls will most likely be easy to convert.

$.post has less features than $.ajax, but internally it uses $.ajax to do the real work.

Kris
and what kind of field i must to set? because when i get html in response nothing happens. it skips both 'success' and 'error'
Konoplianko
you'll have to inspect the response data on success, or header some error response code on the login page (403 forbidden maybe?) so jquery will know it's an error and will use the error callback instead.
Kris