欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

如何在程序中申明AJAX

程序员文章站 2022-07-06 16:26:08
...
<script type="text/javascript">
var ss="";
        var xmlHttp;
           function createXMLHttpRequest() {
            if (window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();               
            }
        }

        function go() {
            createXMLHttpRequest();
            var url = "../ReturnXY";
            xmlHttp.open("GET", url, true);
          
            xmlHttp.onreadystatechange = goCallback;
            xmlHttp.send(null);
        }

        function goCallback() {
       
            if (xmlHttp.readyState == 4) {
            alert(xmlHttp.status);
                if (xmlHttp.status == 200) {
                    ss=xmlHttp.responseText;
                }
            }
        }
       
    function dd()
    {
    alert(ss);
    }
    </script>