Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback only runs on 200 response #215

Closed
etagwerker opened this issue Nov 4, 2016 · 3 comments · Fixed by #216
Closed

Callback only runs on 200 response #215

etagwerker opened this issue Nov 4, 2016 · 3 comments · Fixed by #216

Comments

@etagwerker
Copy link
Contributor

Hi,

I'm not sure if this is an issue, maybe it's a feature request.

gon is working fine and calling my callback when the response is 200 (OK) but it's not calling it when I get response different than 200.

The problem is that we are relying on done to call the callback which only works with successful responses: https://github.com/gazay/gon/blob/master/js/watch.js#L36

I'm wondering if we could have another callback (e.g. errorCallback)

What do you think?

Thanks

@etagwerker
Copy link
Contributor Author

I'm proposing a solution like this:

  performAjax = function() {
    var xhr;
    xhr = $.ajax({
      type: options.type || 'GET',
      url: options.url,
      data: {
        _method: options.method,
        gon_return_variable: true,
        gon_watched_variable: name
      }
    });
    return xhr.done(callback).fail(errorCallback);
  };

And then:

gon.watch = function(name, possibleOptions, possibleCallback, errorCallback) {
  var callback, errorCallback, key, options, performAjax, timer, value, _base, _ref;
  if (typeof $ === "undefined" || $ === null) {
    return;
  }
  ...

@gazay
Copy link
Owner

gazay commented Nov 4, 2016

Hello! Thank you for issue. Can you do a PR?

@etagwerker
Copy link
Contributor Author

@gazay Sure, I can work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants