JavaScript函数关闭

时间:2013-08-01 23:14:48

标签: javascript ajax

我正在尝试创建一个AJAX JavaScript类,代码如下:

// Create a new User object that accept an object of properties
function JsonLoader() {

    function ajaxRequest() {
        var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]; //activeX versions to check for in IE
        if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
            for (var i=0; i<activexmodes.length; i++) {
                try {
                    return new ActiveXObject(activexmodes[i]);
                }
                catch(e) {
                    //suppress error
                }
            }
        }
        else if (window.XMLHttpRequest) // if Mozilla, Safari etc
            return new XMLHttpRequest();
        else
            return false;
    }

    this.loadJosonData = function() {
        var mygetrequest = ajaxRequest();

        mygetrequest.onreadystatechange = function() {
            if (mygetrequest.readyState==4) {
                if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
                    var jsondata=eval("("+mygetrequest.responseText+")"); //retrieve result as an JavaScript object
                } else {
                    alert("An error has occured making the request");
                }
            }
        }

        mygetrequest.open("GET", 'some_url', true);
        mygetrequest.send(null);
    };
}

现在我想使用从AJAX调用返回的jsondata值,返回jsondata变量的最佳方法是什么?

0 个答案:

没有答案