2013-04-18 158 views
0

我有jQuery ajax調用來從服務器獲得結果,併成功,代碼應該調用JavaScript函數,這是不是在jQuery地區的代碼,所以我在螢火蟲中發生錯誤:該函數的調用沒有參考。如何從jQuery ajax調用javascript函數?

這裏是我的代碼(見功能addGMarker Ajax調用):

function test1234(res) { 
    PreInfo = res; 

    popupContentHTML = deviceMoreinfo_callBack_ForGoogle(PreInfo); 

    var sum = '<p>Please, Select <b>[Sensors Reading List]</b> tab to view vehcile sensors reading, and select <b>[Device Communication Commands]</b> tab to send commands for the device:</p><br/>'; 
    var tabs = [ 
new MaxContentTab('Sensors Reading List', maxContentDiv), 
new MaxContentTab('Device Communication Commands', maxContentDivForCommands)]; 

    this.openMaxContentTabsHtml(map, popupContentHTML, sum, tabs, { maxTitle: "Sensors and Features" }); 

    var iw = map.getTabbedMaxContent(); 
    iw.id = this.id; 

    GEvent.addListener(iw, 'selecttab', function (tab) { 
     var node = tab.getContentNode(); 

     switch (tab.getLabel()) { 
      case 'Sensors Reading List': 
       maxContentDiv.innerHTML = '<IMG SRC="../../../images/FullModeIcons/LoadingImage.gif" /> Loading...'; 
       //GetSensorsReading(this.id, ClientID, "En", GetSensorsReading_CallBack); 
       jQuery.ajax({ 
        type: "POST", 
        url: "../../../DevicesManagerAjax.asmx/GetSensorsReading", 
        data: "{Device_ID: '" + this.id + "', ClientID: '" + ClientID + "', Page_ID: 'En'}", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        timeout: 70000, 
        success: function (msg) { 
         var res = msg.d; 
         GetSensorsReading_CallBack(res); 
        }, 
        error: function (xhr, status, errorThrown) { 
         alert("An error occered, " + errorThrown); 
        } 
       }); 
       break; 
      case 'Device Communication Commands': 
       maxContentDivForCommands.innerHTML = '<IMG SRC="../../../images/FullModeIcons/LoadingImage.gif" /> Loading...'; 
       //GetContorolableSensors(this.id, ClientID, "En", GetContorolableSensors_CallBack); 
       jQuery.ajax({ 
        type: "POST", 
        url: "../../../DevicesManagerAjax.asmx/GetContorolableSensors", 
        data: "{Device_ID: '" + this.id + "', ClientID: '" + ClientID + "', Page_ID: 'En'}", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        timeout: 70000, 
        success: function (msg) { 
         var res = msg.d; 
         GetContorolableSensors_CallBack(res); 
        }, 
        error: function (xhr, status, errorThrown) { 
         alert("An error occered, " + errorThrown); 
        } 
       }); 
       break; 
     } 
    }); 
} 


function addGMarker(ID, point, Marker_Icon) { 
    icon = new GIcon(G_DEFAULT_ICON); 

    if (_IconClientID == "0") { 
     if (Marker_Icon == "blue") { 
      if (ID == FollowVechicleID) { 
       icon.image = "../../Images/Icons/" + _Follow_Icon; 
      } 
      else { 

       icon.image = "../../Images/Icons/" + _Normal_Icon; 
      } 

      if (ID == FollowVechicleID) { 
       ShowLastThreePositions(); 
      } 
     } 
     else { 

      icon.image = "../../Images/Icons/" + _Speed_Icon; 
     } 
    } 
    else { 
     if (Marker_Icon == "blue") { 
      if (ID == FollowVechicleID) { 

       icon.image = "../../Images/Icons/ClientsIcons/" + _Follow_Icon; 
      } 
      else { 

       icon.image = "../../Images/Icons/ClientsIcons/" + _Normal_Icon; 
      } 
     } 
     else if (Marker_Icon == "red") { 

      icon.image = "../../Images/Icons/ClientsIcons/" + _Speed_Icon; 
     } 
    } 

    icon.iconSize = new GSize(32, 32); 
    icon.dragCrossSize = new GSize(0, 0); 
    icon.shadowSize = new GSize(32, 32); 
    icon.iconAnchor = new GPoint(5, 5); 


    marker = new GMarker(point, icon); 
    marker.id = ID; 


    GEvent.addListener(marker, 'click', 
     function() { 
      popupContentHTML = Device_Option_forGoogle(this.id); 
      this.openInfoWindowHtml(popupContentHTML); 
     } 
     ); 

    GEvent.addListener(marker, 'mouseover', 
         function() { 
          //PreInfo = getDeviceInfoForPopUp(this.id, ClientID, "En"); 

          jQuery.ajax({ 
           type: "POST", 
           url: "../../../DevicesManagerAjax.asmx/getDeviceInfoForPopUp", 
           data: "{deviceID: '" + this.id + "', IDclient: '" + ClientID + "', Page: 'En'}", 
           contentType: "application/json; charset=utf-8", 
           dataType: "json", 
           timeout: 70000, 
           success: function (msg) { 
            var res = msg.d; 
            test1234(res); 
           }, 
           error: function (xhr, status, errorThrown) { 
            alert("An error occered, " + errorThrown); 
           } 
          }); 



         }); 



    var markers = []; 
    markers.push(marker); 

    mgr.addMarkers(markers, 0); 
    mgr.refresh(); 
    ClientPOI.refresh(); 
    POImgr.refresh(); 
} 
+2

您粘貼的代碼片段相對較長。你能否嘗試縮小一點以突出實際的問題點? – jsalonen

+0

♪♫深,寬,深,寬,有一個代碼示例滾動深和廣泛♫♪ –

+0

@JamesHill *您沒有足夠的聲譽發表您的評論在音頻格式。* – 2013-04-18 11:22:05

回答

0

這是從jQuery的調用Javascript函數相同的代碼。它工作正常。問題在代碼中的其他地方。

這可能不是一個確切的解決方案,但不能從解決方案轉移。

function test1234(res) { 
    alert(res) 
} 

function Test() { 
    jQuery.ajax({ 
      type: "POST", 
      url: "/TestWebApp/ProcessServlet.do", 
      success: function (res) { 
       alert(res); 
       test1234(res); 
      }, 
      error: function (xhr, status, errorThrown) { 
       alert("An error occered, " + errorThrown); 
      } 
    }); 
} 
+0

我得到這一行錯誤:this.openMaxContentTabsHtml(map,popupContentHTML,sum,tabs,{maxTitle:「Sensors and Features」}); –