As a junior javascript developer, I am working on creating my own "basic" javascript framework inspired by jQuery
. I am particularly fond of method chaining instead of callbacks, but I am finding it challenging to implement this.
Currently, I have developed my own version of an ajax
"class", but I am struggling to replicate the functionality of .done()
used in jQuery.
My goal is to have a syntax like this to eliminate callback hell:
ajax(url, type, data).success(function(response){});
However, when I try this, the response
ends up being false
because it is called before the ajax request is complete.
I attempted to implement a promise, but I encountered syntax errors and vague error messages like uncaught (in promise) OK
.
This is the current state of my code:
// Code snippet
-- My serialize function:
// Code snippet
-- NOTE:
I am aiming to use the ajax function in this manner:
ajax(url, type, data).success(function(response){
// Handle responseData before the callback
// On success
}).error(function(error){
// On error
});
-- This does not necessarily have to involve promises. Any alternative methods are acceptable, as I am open to exploring different approaches.