$.ajax promises

I see you have implemented the A+ promise in ajax but promises should only return one argument
What you have is jqXHR.then(function( data, textStatus, jqXHR ) {}

This prevents you from using async/await since only the first argument are assigned

let data = await jqXHR
// but what about textStatus and xhr?
// ideally 
let [data, textStatus, xhr] = await jqXHR
// but this means the promise must resolve an array... You could also resolve an object
let {data} = await jqXHR

I’m starting to use the fetch api more and more so $.ajax only feels like a extra dead wight… Would love it if you go more towards a fetch-alike api

Author: Fantashit

1 thought on “$.ajax promises

  1. If you need jQuery.ajax, a workaround is to change:

    let [data, textStatus, xhr] = await jqXHR;

    to:

    let [data, textStatus, xhr] = await jqXHR.then((...args) => args);

Comments are closed.