brianleroux / xui

A tiny javascript framework for mobile web apps.
http://github.com/xui/xui
391 stars 159 forks source link

xhr callback for onerror #24

Closed aglemann closed 13 years ago

aglemann commented 14 years ago

Only executes the callback if status OK, should pass the status as first param to callback and always execute on completion (no handling for when the request goes bad).

Thanks!

yoka commented 13 years ago

I'd rather use onsuccess / onerror callbacks to keep success and error logic away from each other.. any specific reason (cross platform support or..?) for missing this behaviour?

gryzzly commented 13 years ago

perhaps doing this in /src/js/xhr.js:

+++ if((/^[45]/).test(req.status)) req.handleError(req); // pass XHR object (req) to handleError
--- if((/^[45]/).test(req.status)) req.handleError();

would allow to access XHR object in xhr.error method lile:

trigger.xhr(this.parentNode.action, {
      method: 'post',
      error: function(xhr) {
        if (xhr.status == 401) {
          // not authorized
          location.href = '/login';
        }
      },
      ...

I have done this in my fork and it seem to work. What's the way for this to land in origin here?

brianleroux commented 13 years ago

best way would be to fork at github.com/xui/xui and submit a pull request.