2013-04-18 40 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”}); –