开发者

why this javascript only works in IE explorer

hi i don't know why this script only works on internet explorer, exactly in the method that returns from ajax called. take a look to the script

function saveMap() {

if (confirm("Esta seguro de guardar el mapa?")) {
//        alert("Estas en el centro:" + map.getCenter().toString() + "Con zoom: " + map.getZoom().toString());
    var mapData = new Array(map.getCenter().lat().toString(),
                            map.getCenter().lng().toString(),
                            "Esto es una prueba",
                            map.getZoom().toString());
    $.ajax({
        type: "POST",
        url: "SaveMap.aspx/saveMapData",
        data: "{mapData: '" + mapData + "'}",
        contentType: "applic开发者_如何学JAVAation/json; charset=utf-8",
        dataType: "json",
        success: function (flag) {

            //this block of code only works in IE
            if (flag)
                alert("Se guardo el mapa de manera correcta");
            else
                alert("Ocurrio un error en la ejecucion"); 
        }
    });    
}
}

this the signature of my method in aspx.net

[WebMethod()]
public static bool saveMapData(string mapData) 
{ 
    //do something
    return true;
}


I've got one idea why script is working in IE but not in other browsers. First take a look here (also here) and you will find that json returned from you ASP.NET WebMethod begins with d:

{"d":"something_json"}

So in your place I would do something like that:

success: function (flag) {

            //this block of code only works in IE
            if (flag.d)
                alert("Se guardo el mapa de manera correcta");
            else
                alert("Ocurrio un error en la ejecucion"); 
        }

I may think that is because IE is Microsoft software and can read json and {"d":"something_json"} better than other browsers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜