日期:2014-05-18  浏览次数:20730 次

AJAX获取服务器数据失败 告急
近帮人做个网站,发现AJAX读取服务器数据老师失败,不知道是本地IIS问题还是。
http://center.smesd.gov.cn/util?o=areaselect&supercode=1030
上面是服务器地址,在浏览器中可以返回数据。

大家帮忙看看下面代码,或者有获取到数据并解析出来的支个招。。。


方式一:失败,改了好几种格式都不行。

function getcitylist1() {
            $.ajax({
                url: "http://center.smesd.gov.cn/util?o=areaselect&supercode=1030",
                dataType: "text/html",
                data: "",//
                beforeSend: function(x) {
                    x.setRequestHeader("Content-Type", "text/html; charset=utf-8");//
                },
                success: function(json) {
                    alert(json.d);
                },
                error: function(x, e) {
                    alert(x.responseText);
                },
                complete: function(x) {
                    alert(x.responseText);
                }
            });
                        
        }


方式二:原始js完成的ajax,获取失败,用chrome查看了协议返回信息。

function createXmlHttp(){//创建AJAX(XmlHttpRequest)
        var XmlHttp = false;
        try{
        XmlHttp = new XMLHttpRequest();
        
        }catch(e1){
        try{
        XmlHttp = new ActiveXObject("Microsoft.XmlHttp");
        }catch(e2){
        try{
        XmlHttp = new ActiveXObject("Msxml2.XmlHttp");
        }catch(e3){
        XmlHttp = false;
        }
        }<