首页 > 代码库 > Ajax嵌套调用 (jquery) $.ajaxSettings.async = false;

Ajax嵌套调用 (jquery) $.ajaxSettings.async = false;

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title></title>    <script src=http://www.mamicode.com/"../javascripts/jquery-2.1.4.js"></script>    <script>        window.onload = function () {             $.post("Handler.ashx", { flag: 1 }, function (_data) {                if (_data) {                    var html = "";                    html += "<table border=‘1‘>";                    for (var i = 0; i < _data.length; i++) {                        var pj00401 = _data[i].pj00401;                        html += "<tr>";                        html += "<td>" + _data[i].pj00402 + "</td>";                        html += "<td>" + getHtml(pj00401) + "</td>";                        html += "</tr>";                    }                    html += "</table>";                    $("#div1").append(html);                }            }, "json");              var getHtml = function (_pj00401) {                 var _html = "";                $.ajaxSettings.async = false;//重要设置                $.get("Handler.ashx", { flag: 102, pj00401: _pj00401 }, function (_data) {                    if (_data) {                        _html = "<table>";                        _html += "<tbody> ";                        for (var i = 0; i < _data.length; i++) {                            _html += "<tr>";                            _html += "<td>" + _data[i].pj00402 + "</td>";                            _html += "</tr>";                        }                        _html += "</tbody>";                        _html += "</table>";                    }                }, "json");                return _html;            }                     }    </script></head><body>    <div id="div1"></div></body></html>

 

Ajax嵌套调用 (jquery) $.ajaxSettings.async = false;