2011-05-23 52 views
1

嗨,我不知道爲什麼這個腳本只適用於Internet Explorer,完全在從ajax調用返回的方法。看看到腳本爲什麼這個JavaScript只適用於IE瀏覽器

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: "application/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"); 
     } 
    });  
} 
} 

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

當代碼不起作用時會發生什麼?有關該問題的更多詳細信息將有所幫助。 – Andy 2011-05-23 15:01:07

+0

您試過哪些瀏覽器除IE外?這工作在什麼版本的IE?您在其他瀏覽器中無法正常工作的錯誤是什麼? – Matt 2011-05-23 15:01:38

+0

@Andy當我調試我看到的工作代碼。但只有當我在瀏覽器中調試腳本。但不要利用或什麼 – Jorge 2011-05-23 15:03:33

回答

1

我有一個想法我的方法的aspx.net簽名爲什麼腳本工作在IE瀏覽器而不是在其他瀏覽器。先取a look herealso here),你會發現,從JSON返回你的WebMethod ASP.NET開始d:

{"d":"something_json"} 

所以在你的地方,我會做這樣的事情:

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"); 
     } 

我可能會認爲這是因爲IE是微軟的軟件,可以比其他瀏覽器更好地閱讀json和{"d":"something_json"}

+0

@Jorge在斷點調試時,WebMethod是否進入'SaveMap.aspx/saveMapData'方法體? – 2011-05-23 15:16:45

+0

@Jorge其次請把你的WebMethod簽名,甚至源代碼。乾杯! – 2011-05-23 15:18:15

+0

@ r.piesnikowski是的asp方法的工作和mi方法它的方法,我會把它放在我的問題給我一秒鐘來修改內容 – Jorge 2011-05-23 16:29:40

相關問題