javascript正确加载只有警报

时间:2015-04-13 13:00:39

标签: javascript jquery ajax json html5

var serviceURL = "http://test.foodiesbuddy.com/";
var temp = "";
var cars = [];
one();

function one() {
    var temp = "";
    $.ajax({
        type: "GET",
        async: false,
        cache: false,
        url: serviceURL + 'phonegap/getdetails.php',
        dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
        data: {
            'function': 'categories',
            'username': "pizzahut"
        },
        timeout: 20000,
        success: function (data) {
            $.each(data["posts"], function (index, hotel) {
                aadf(index, hotel.category_id);
                j = index;
                alert(hotel.category_id); <!---1st alert--->
                    cars[index] = hotel.category_name;
            });
            localStorage["names"] = JSON.stringify(cars);
            //  comp();
            localStorage.setItem("lindex", j);
            window.location.href = 'ind.html'; <!---to load next page-->
        },
        error: function () {
            alert("snap! Something went wrong.");
        },
    });
}

function aadf(asdf, zxc) {
    var i = asdf;
    var serviceURL = "http://test.foodiesbuddy.com/";
    $.ajax({
        type: "GET",
        async: false,
        url: serviceURL + 'phonegap/getdetails.php',
        dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
        data: {
            'function': 'menu',
            'category_id': zxc
        },
        timeout: 20000,
        success: function (data) {
            qw = "submenu" + zxc;
            de = "description" + zxc;
            lp = "large" + zxc;
            mp = "medium" + zxc;
            sp = "small" + zxc;
            ls = "lserves" + zxc;
            ms = "mserves" + zxc;
            ss = "sserves" + zxc;            
            qw = [];
            de = [];
            lp = [];
            mp = [];
            sp = [];
            ls = [];
            ms = [];
            ss = [];

            $.each(data["posts"], function (index, hotel2) {
                qw[index] = hotel2.menu_name;
                de[index] = hotel2.description;
                lp[index] = hotel2.price;
                mp[index] = hotel2.mprice;
                sp[index] = hotel2.sprice;
                ls[index] = hotel2.serve_for;
                ms[index] = hotel2.mserve_for;
                ss[index] = hotel2.sserve_for;
                r = index;                
            });
            alert(qw); <!-- 2nd alert i mentoned--->
            window.localStorage.setItem("lin" + i, r);
            window.localStorage["nam" + i] = JSON.stringify(qw);
            window.localStorage["datrs" + i] = JSON.stringify(de);
            window.localStorage["lprice" + i] = JSON.stringify(lp);            
            window.localStorage["mprice" + i] = JSON.stringify(mp);
            window.localStorage["sprice" + i] = JSON.stringify(sp);
            window.localStorage["lserves" + i] = JSON.stringify(ls);
            window.localStorage["mserves" + i] = JSON.stringify(ms);
            window.localStorage["sserves" + i] = JSON.stringify(ss);            
        },
        error: function () {
            alert("snap! Something went wrong.");
        },
    });    
}

如果我发出2警报,则只保存localstorage数据并将其发送到下一页,如果警报被删除,则继续下一页而不设置本地存储

0 个答案:

没有答案