Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.

Programming and Learning from SD

Edit: 5/4/2020, I moved this to

I’m trying to move away from jQuery, since I’m using Knockout and AngularJS more all the time. I’ve always done my AJAX calls with the useful jQuery $.ajax( method.

Searching for “ajax without jquery” brings up a lot of results, but they all include how to do it with jQuery.

First a friend found a tutorial on ES6 promises on HTML5 rocks that included an example of “Promisifying XMLHttpRequest”. Since promises aren’t in all browsers yet (IE and Android Browser) you can polyfill with es6-promise. Or use Q or Bluebird for a promise implementation. Angular JS has it’s own $http and $q to handle this.

There is also a question on StackOverflow that I added this answer to.

Wrap that in a dataService.js file and I’ll be well on my way to no longer needing jQuery for Ajax calls and still have promises!

Update: This project on Github has a simple wrapper of XHR with promises added in.

Update 2: Fetch is going to be an XMLHttpRequest replacer though it’s a ways off in browser support.

Posted on Tuesday, October 7, 2014 4:20 PM Knockout Js , JavaScript , jQuery , AngularJS | Back to top

Comments on this post: Ajax promises without jQuery

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Aligned | Powered by: