Closed grrowl closed 11 years ago
Actually, I'm finding that with async set to true
, my error callback is firing twice before the success callback fires. Could you shed some light on this?
Hmmm... Can I see your ajax request, minus the url?
It seems to be a problem with request.onreadystatechange = handleResponse
: if error
is defined on line 63 (which it always is, to either options.error
or $.noop
) it will fire on any statechange that isn't a final success. (Chrome 30)
here's my request code, using chocolatechip-3.0.5.js
$.ajax({
url: baseUrl + sourceKey,
async: true,
success: function onRequestSuccess(data) {
console.log('got success', data);
},
error: function (xhr) {
console.error("Couldn't fetch "+ sourceKey, xhr, navigator.onLine);
}
});
OK, tell me if I've got this right. I want to set up an ajax request with error handling. If there's an error, it should fire twice. Well, it shouldn't, but that's the situation you're dealing with. Right?
I would expect it to fire either the success or error callback once, only when the request is complete. Synchronous Ajax only fires one onreadystatechange because the js execution for the whole page is paused until the request completes.
On Monday, 11 November 2013, sourcebits-robertbiggs wrote:
OK, tell me if I've got this right. I want to set up an ajax request with error handling. If there's an error, it should fire twice. Well, it shouldn't, but that's the situation you're dealing with. Right?
— Reply to this email directly or view it on GitHubhttps://github.com/sourcebitsllc/chocolatechip-ui/pull/4#issuecomment-28167334 .
Yeah, but at the moment you’re saying it’s firing twice for an error, though not for the success.
On Nov 10, 2013, at 5:42 PM, Tom McKenzie notifications@github.com wrote:
here's my request code, using chocolatechip-3.0.5.js
$.ajax({ url: baseUrl + sourceKey, async: true, success: function onRequestSuccess(data) { console.log('got success', data); }, error: function (xhr) { console.error("Couldn't fetch "+ sourceKey, xhr, navigator.onLine); } });
— Reply to this email directly or view it on GitHub.
Sorry I may have been unclear — it fires two errors then the success.
On Monday, 11 November 2013, sourcebits-robertbiggs wrote:
Yeah, but at the moment you’re saying it’s firing twice for an error, though not for the success.
On Nov 10, 2013, at 5:42 PM, Tom McKenzie <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>> wrote:
here's my request code, using chocolatechip-3.0.5.js
$.ajax({ url: baseUrl + sourceKey, async: true, success: function onRequestSuccess(data) { console.log('got success', data); }, error: function (xhr) { console.error("Couldn't fetch "+ sourceKey, xhr, navigator.onLine); } }); — Reply to this email directly or view it on GitHub.
— Reply to this email directly or view it on GitHubhttps://github.com/sourcebitsllc/chocolatechip-ui/pull/4#issuecomment-28167548 .
Let me get this straight, you’re getting your error callback firing twice when the success files? Let me set up some tests to see if I can spot something. This is a new one for me. On Nov 10, 2013, at 5:56 PM, Tom McKenzie notifications@github.com wrote:
Sorry I may have been unclear — it fires two errors then the success.
On Monday, 11 November 2013, sourcebits-robertbiggs wrote:
Yeah, but at the moment you’re saying it’s firing twice for an error, though not for the success.
On Nov 10, 2013, at 5:42 PM, Tom McKenzie <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>> wrote:
here's my request code, using chocolatechip-3.0.5.js
$.ajax({ url: baseUrl + sourceKey, async: true, success: function onRequestSuccess(data) { console.log('got success', data); }, error: function (xhr) { console.error("Couldn't fetch "+ sourceKey, xhr, navigator.onLine); } }); — Reply to this email directly or view it on GitHub.
— Reply to this email directly or view it on GitHubhttps://github.com/sourcebitsllc/chocolatechip-ui/pull/4#issuecomment-28167548 .
— Reply to this email directly or view it on GitHub.
console.log('start ajax');
$.ajax({
url: baseUrl + sourceKey,
async: true,
success: function onRequestSuccess(data) {
console.log('success callback');
},
error: function (xhr) {
console.log('error callback', xhr.readyState);
}
});
that logs:
start ajax
error callback 2
error callback 3
success callback
I would suggest adding a conditional only fire the error callback on a known error state (xhr complete with 400/500 code, xhr.readyState equals an error state (not "in progress")
no, he’s just a user.
On Nov 10, 2013, at 6:30 PM, Tom McKenzie notifications@github.com wrote:
$.ajax({ url: baseUrl + sourceKey, async: true, success: function onRequestSuccess(data) { console.log('success callback'); }, error: function (xhr) { console.log('error callback', xhr.readyState); } });
that logs:
remoteData fetching bodyTypes error callback 2 error callback 3 success callback I would suggest adding a conditional only fire the error callback on a known error state (xhr complete with 400/500 code, xhr.readyState equals an error state (not "in progress")
— Reply to this email directly or view it on GitHub.
How did you get on this thread? :-P
On Nov 10, 2013, at 6:30 PM, Tom McKenzie notifications@github.com wrote:
$.ajax({ url: baseUrl + sourceKey, async: true, success: function onRequestSuccess(data) { console.log('success callback'); }, error: function (xhr) { console.log('error callback', xhr.readyState); } });
that logs:
remoteData fetching bodyTypes error callback 2 error callback 3 success callback I would suggest adding a conditional only fire the error callback on a known error state (xhr complete with 400/500 code, xhr.readyState equals an error state (not "in progress")
— Reply to this email directly or view it on GitHub.
Haha, reply by email hey!
I work at an agency in Melbourne writing a web and phonegap app. Looks like you could use a hand with parts of ChUI though.
Arggg!!! Somehow this got merged by cloud services with my other email accounts. Should be alright now.
So, I have this at the moment: $(function() { $.ajax({ url: 'data/perfumes.json', async: true, dataType: 'json', success: function(data) { data.ladies.forEach(function(ctx, idx) { $('#ladiesPerfumes').append(processCategoryTmpl(ctx, idx)); }); console.log('success callback'); }, error : function (data) { console.log('There was an error!'); } }); function processCategoryTmpl(ctx, idx) { return "<li class='comp'>\ <aside><img src='" + ctx.img_prev + "'></aside>\ <div>\ <h3>" + ctx.product_title + "</h3>\ <h4>" + ctx.short_description + "</h4>\ </div>\ <aside><span class='value'>" + ctx.wholesale_price + "</span></aside>\ </li>"; } });
It's giving me exactly one success result and log. On error, though, I'm getting several error logs. That doesn't make sense. We were planing on totally rewriting the ajax part anyway to take advantage of deferred objects and promises, so I'm going to fast track that now.
In the mean time, since you're having such a problem with the weird Ajax behavior, I'd suggest switch out to jQuery to see if that solves the problem. For you on the client side, there is no difference between using jQuery or ChocolateChipJS. ChUI abstracts those differences for you. Use jQuery 2.0.3, it's been optimized for mobile and modern browsers, it's somewhat smaller and more performant than previous versions of jQuery.
That would be a very welcome change. I'll investigate switching to jQuery, I've worked around a bunch of CCJS's idiosyncrasies and we're about 70% done with the JS, so it might make sense just to custom write the AJAX stuff (to handle onLine/offLine events, etc).
Thanks for your help.
I wouldn't think you'd have much trouble switching. HOWEVER, if you have a problem, give me a shout out. rbiggs@ymail.com Skype: rombiggs
By the way, groups.google.com is the best place to reach out with problems. the group name is chocolatechipui.
Yup I've made a couple of posts on there (as Tom McKenzie) but didn't want to litter it with bug reports.
I was going to say just use Github's issues link, but I'm not seeing it anywhere. Did they remove that feature?
No, but it might have been turned off — under the repo's Settings page, turn on "Issues" under Features.
On Mon, Nov 11, 2013 at 4:45 PM, sourcebits-robertbiggs < notifications@github.com> wrote:
I was going to say just use Github's issues link, but I'm not seeing it anywhere. Did they remove that feature?
— Reply to this email directly or view it on GitHubhttps://github.com/sourcebitsllc/chocolatechip-ui/pull/4#issuecomment-28175867 .
Yup just turned it on. You should see it now. You can post all issues there please.
Otherwise the UI will hang while the request is being filled (sensible default)