Encapsulate an ajax request, which successfully returns a promise function, how to call the method in the page and execute the promise callback

clipboard.png

clipboard.png
this call will report an error that then is not defined

Mar.21,2022

is written as follows:

return new Promise(res, rej) {
    res(data);
}

you $.ajax itself returns a Promise you can directly return out. If you do not do data processing, there is no need to encapsulate a layer of Promise


.

Brother, you used it wrong. Look, I just wrote a rough idea. Promise wraps the whole thing

function get(){
    return new Promise(function(resolve,reject){
    let rootId = 
    
    $.ajax()
    
        if(data.status == 200){
            resolve()
        }
        else{
            reject()
        }
    })
}
get().then(res =>{}).catch(res=>{})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31a68-4d44d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31a68-4d44d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?