私信  •  关注

spratap124

spratap124 最近创建的主题
spratap124 最近回复了
5 年前
回复了 spratap124 创建的主题 » 如何记忆jquery-ajax响应?

感谢@phil h的帮助,我用承诺解决了找不到的错误。

function getDataById(url, cache) {

            return new Promise(function(resolve, reject){
                $.ajax({
                    method: "GET",
                    url: url,
                    success: function (data) {
                        console.log("ajax data", data);
                        console.log("cache", cache);
                        cache[url] = data;
                        resolve(data)
                    },
                    error:function(err){
                        reject(err);
                    }
                });
            });
        }

在服务器调用中

 else {
                    console.log("loading from server");
                    fn(url, cache).then(function(response){
                        console.log("response", response);
                         changeTitle(response);
                    });