Skip to main content
13 events
when toggle format what by license comment
Sep 19, 2017 at 10:34 vote accept shorif2000
Sep 19, 2017 at 10:00 comment added shorif2000 @Joseph I have managed to get fetch working however i have cloned the fetch polyfill from github, included the fetch.js file after jquery but it is not working in IE11. Am i missing anything else?
Aug 18, 2017 at 12:13 comment added Joseph @shorif2000 As mentioned in my previous comment, there is a polyfill for it. And I'm not sure what you mean by "fetch is not an async call but a normal request". fetch is asynchronous. What's probably missing are cookies, which fetch omits and for you to explicitly supply.
Aug 18, 2017 at 11:19 comment added shorif2000 @Joseph i just saw IE 11 is not compatible with fetch so its not something i can use
Aug 18, 2017 at 10:53 comment added shorif2000 @Joseph I realise fetch is hitting my SSO page which is returning html login page. this would not occur on a $.get as it checks the csrf to make sure it is valid. also noticed fetch is not an async call but a normal request. If I paste the url into my browser i get valid json on the screen but using the fetch hits my SSO
Aug 17, 2017 at 13:28 comment added I wrestled a bear once. I will say the whole bit about the anonymous functions doing nothing but calling functions of the same name is a little.. redundant though.. i would have suggested ust renaming the functions if you had to do it like that.. genProtocolList: generateProtocolList,
Aug 17, 2017 at 13:25 comment added I wrestled a bear once. @Joseph - You wouldn't use a <font> or a <center> in your markup, right? Those are semantically incorrect and should be done with CSS. Same reason you don't put CSS and JS in an HTML file. Semantically, functional code should go in a function, preferably avoiding literals entirely and using prototype. It's not just semantics though, it looks nicer. When I see a literal I expect data, not functions.
Aug 17, 2017 at 12:46 comment added Joseph @Iwrestledabearonce. True, iife does allow "private" methods and variables. The net result is an object of functions in both cases (I declare a literal, OP's iife returns an object of functions). However, my suggestion holds no private members making an iife useless. No need to enforce a concept that's not needed. It only adds noise to the code.
Aug 17, 2017 at 12:39 comment added I wrestled a bear once. Sorry, had to downside for that one little comment about skipping the anon function and just using an object of functions. That kind of code makes me cringe. Plus the whole purpose of the iife is it allows for "private" methods and variables. You can't just swap one for the other in all cases.
Aug 17, 2017 at 12:26 comment added Joseph @shorif2000 For the first comment, fetch is fairly new. If you're using an older browser, that might be the cause. Refer to compatibility tables for details. There are also polyfills available in the wild. As for the latter, it's most likely your endpoint responded with HTML when fetch expected JSON. This usually happens when a JSON endpoint responds with an HTML error page. This is something your server should do consistently, and not for the JS to fix.
Aug 17, 2017 at 9:06 comment added shorif2000 I set the body to null to see how it works but then i get error in Promise.all part SyntaxError: Unexpected token < in JSON at position 0 around .then(([ statuses, protocols ]) => {
Aug 17, 2017 at 9:02 comment added shorif2000 Hi, thanks, im getting this error stackoverflow.com/questions/34692554/…. Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body
Aug 17, 2017 at 2:16 history answered Joseph CC BY-SA 3.0