当前位置:编程学习 > C#/ASP.NET >>

简单的js问题


function postData(postString, postUrl) {

    var xmlHttp = createXml();
    xmlHttp.open("POST", postUrl + "&n=" + Math.random(), true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(postString);
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
                return xmlHttp.responseText;

        }
    }
    
    if (xmlHttp.readyState == 1) { //document.getElementById('out').innerText = '请求已提出(调用 send() 之前)';
        return  "请求已提出";
    }
    if (xmlHttp.readyState == 2) { //document.getElementById('out').innerText = '请求已发送(这里通常可以从响应得到内容头部)';
        return  "请求已发送";
    }
    if (xmlHttp.readyState == 3) { //document.getElementById('out').innerText = '请求处理中(响应中通常有部分数据可用,但是服务器还没有完成响应)';
        return "请求处理中";
    }

 }


一段ajax function 当使用这个方法的时候 xmlHttp.readyState 不同时刻 不同的值  但是return时候function就终止了 所以引用这个function显示的内容都是 “请求已提出”

如何修改这个return 可以不让终止
我知道可以用 把return 换成document.xxxx.innerHTML=''就可以 但是相统一一个方法 所以有什么好的方法么 --------------------编程问答--------------------

function postData(postString, postUrl) {

    var xmlHttp = createXml();
    xmlHttp.open("POST", postUrl + "&n=" + Math.random(), true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(postString);
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
                return xmlHttp.responseText;

        }
    }
    var result;
    if (xmlHttp.readyState == 1) { //document.getElementById('out').innerText = '请求已提出(调用 send() 之前)';
        result="请求已提出";
    }
    if (xmlHttp.readyState == 2) { //document.getElementById('out').innerText = '请求已发送(这里通常可以从响应得到内容头部)';
        result="请求已发送";
    }
    if (xmlHttp.readyState == 3) { //document.getElementById('out').innerText = '请求处理中(响应中通常有部分数据可用,但是服务器还没有完成响应)';
        result= "请求处理中";
    }
   //你既然不想让if内的retun结束方法,那就在此进行后续的操作
   //最后在return


    retrun result;
 }
--------------------编程问答-------------------- 到JavaScript论坛去问 --------------------编程问答--------------------
引用 1 楼 q107770540 的回复:
JScript code

function postData(postString, postUrl) {

    var xmlHttp = createXml();
    xmlHttp.open("POST", postUrl + "&n=" + Math.random(), true);
    xmlHttp.setRequestHeader("Content-Type……
这样的话 饮用方法是没法显示已提出 已发送这些文字的 --------------------编程问答-------------------- ????
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,