Js ajax request problem.

in the project, request background data through ajax and do data processing. Finally, the processed data will be returned. The code looks like this:

function funOne(){
    var htmlStr = "";
    $.get(href,{},function(r){
        var data = eval("(" + r + ")");
        $.each(data,function(k,v){
            /*     */
            htmlStr += "<div>" + v + "</div>";
        })
    })
    return htmlStr;
}
ajax 
 while 
Feb.28,2021

write

var getData = new Promise(function (resolve, reject) {
    $.get(href, {}).then(function (res) {
        if (res) {
            var data = JSON.parse(res);
            //   htmlStr ...
            resolve(htmlStr);
        } else {
            reject(err);
        }
    })
})

getData.then((htmlStr ) => {
    console.log(htmlStr )
}).catch((err) => {
    console.log(err)
})

$.get (href, {}, function (r) {

)
var data = eval('(' + r + ')');
$.each(data,function(k,v){
    /*     */
    htmlStr += '<div>' + v + '</div>';
})
 return htmlStr;

})


function funOne() {
    var htmlStr = '';
    return $.get(href, {}).then(function (r) {
        var data = eval('(' + r + ')');
        $.each(data, function (k, v) {
            /*     */
            htmlStr += '<div>' + v + '</div>';
        })
        return htmlStr;
    })
}

funOne().then(function(htmlStr){
    console.log(htmlStr)
})
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-1b3161c-2bd7f.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-1b3161c-2bd7f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?