-
Notifications
You must be signed in to change notification settings - Fork 753
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
show any ajax request errors to the user in the table #349
Conversation
does === cover it or should the match just be fixed to be a regex? I'm only asking cause I haven't run into this yet, and I'd like to test/understand it. though I do agree using match on a string won't work, I'm just not convinced === is right either here. Does either url use the protocol? are they url or uri? etc etc |
Hey @TheSin- , The url and settings.url instances are just Strings. The code is just checking that the url String is the same, i.e. request matches the expected one in settings. Which, they should be as they are the same string copied around. So i just did a |
right I assumed just strings, but could url be http://example.com/ and settings.url be example.com or one a url and the other a uri? Is there a point where === wouldn't work and something like /url/ would be preferable? Again I haven't been in that part of the code yet, I might try and setup a test on this today if monday would leave me alone for a bit ;) Chances are I'll merge your changes today but I just want to make sure. |
My understanding is that the settings.url of the ajax request is derived from the url method of the pager instance. So they should not differ as on each ajax request the I left the check in there as i wasn't 100% on the edge cases. You can test it easily by just getting your server to return a fail header and the ajax error event should run. |
In all my tests they were identical, and they are the uri not the url, but they do not include the protocol unless it's actually specified in the ajaxUrl. This seems like a good find and fix, I'm going to accept it. |
show any ajax request errors to the user in the table
I'm probably going to have to revert this change as the
and a log of those two values, you'll see:
so a match might be the best solution. I'm open to any feedback. :) |
this was my concern and I'm glad you caught it Rob. |
Hi, I can't reproduce the same results. I get the same value for I haven't traced the execution of this for a while but my original understanding was the url was set on the ajaxObject prior to the remote request see lines 291 - 314: // line 306
c.ajaxObject.url = url;
// line 314
$.ajax(c.ajaxObject); Thus they "should" always be the same in the Perhaps I am missing something.. |
I get it when I test it locally (in Firefox; Chrome doesn't work locally). I take this pager ajax demo: http://mottie.github.io/tablesorter/docs/example-pager-ajax.html change the and add this within the error event: $doc.bind('ajaxError.pager', function(e, xhr, settings, exception) {
console.log(url, settings.url); the log shows:
and the table is showing the error row with "Not connected, verify Network" - after I changed it to |
Pretty sure you can't use the '#' char for query params delimiting as the '#' char refers to the fragment part of a URL and the '?' char delimits the query part (http://dev.w3.org/html5/spec-LC/urls.html). In my tests using the '?' char instead of the '#' i got the same URL in the error function. E.g.:
Perhaps the query params are being stripped by the JQuery ajax command and thus the settings.url is different to the derived URL from the |
You're right, I should be using the |
And I do agree with that, there is a chance that # is used since it's not illegal char, it means to load the page at that tag, so it is possible which means the compare would fail in some rare cases, it's best to find a way so all cases work. That being said it will be a rare case I don't think we need to revert the change, I think this change passes more then the old way, thus isn't still an improvement, though we should add a comment about the potential fail and work on a 100% fix for it in the future. At least that is my opinion. |
I agree that the '#' char can be a valid URL component for ajax requests but it's poor practice (as the original intention was to signify the fragment in the document). But who am I to tell people what to have in their URL's! Instead how about an explicit encode of any '#' char in the URL returned from c.ajaxUrl on Line 319. Perhaps: var url = (c.ajaxUrl) ? c.ajaxUrl
// allow using "{page+1}" in the url string to switch to a non-zero based index
.replace(/\{page([\-+]\d+)?\}/, function(s,n){ return c.page + (n ? parseInt(n, 10) : 0); })
.replace(/\{size\}/g, c.size) : '', Becomes: var url = (c.ajaxUrl) ? c.ajaxUrl
// allow using "{page+1}" in the url string to switch to a non-zero based index
.replace(/\{page([\-+]\d+)?\}/, function(s,n){ return c.page + (n ? parseInt(n, 10) : 0); })
.replace(/\{size\}/g, c.size)
// manually encode any '#' char with the encoded value(%23), http://www.w3schools.com/tags/ref_urlencode.asp
.replace(/#/g, "%23") : '', In some quick manual tests this seems to allow the Thoughts? |
I completely agree it's poor practice, but as I have learn from coding for the company I work for currently, you must always code for the lowest common denominator if you want to have full support. In my case the bar is set very very low ;) I'like to say that using a percent code (or urlencoding) wouldn't be a good solution but since I still dont' know the full scope of those vars it's hard for me to comment. But at least now we have options that we can test with. The real question is... is that the only char that could cause this issue? |
How about this (http://dev.w3.org/html5/spec-LC/urls.html#url-manipulation-and-creation):
Also this:
|
what about a regex instead? something to just make sure the start of c.ajaxObject.url = url so like /^c.ajaxObject.url/, then it doesn't matter what the end of the url is, even if it has hash tags on the end. etc etc. |
The match I had in there before worked fine. Is it really a problem to keep it as a match? |
Sorry @Mottie, the original match didn't work! Please note: the original intention of my pull request is to display error notifications on failing ajax requests. As per my initial comments on the pull request, using the Originally when looking at the code, I questioned why there is a URL match in the error object but decided to leave it alone and just make the code work. Now looking again (noting the many issues with the match function and valid URL's, etc), I dont' think you need to double check the URL if the Ajax error event is fired. This event should only fire if the ajax request fails and the URL should be the one loaded here, Accordingly, I think the URL check is unnecessary defensive programming. If the ajax event fails then just show an error (as stated above, the attempted request URL should be the one that was loaded, minus invalid url chars, etc). Perhaps I am not fully understanding the relevance of the URL match defence before showing the error on the table. |
LOL I was having trouble remembering why I did that too... then I found out it was written by someone else - see pull request #183. I guess it wouldn't hurt to remove it ;) |
The ajaxError event is testing the url matches the stored settings url using the String.match function which expects a regular expression as it's parameter. Instead use the equality operator to test the strings match, thus allowing the ajax error response message to be shown on the table.