0

我有 jQuery ajax 调用来从服务器获取结果,并且在成功时,代码应该调用不在 jQuery 区域代码中的 javascript 函数,所以我在 firebug 中遇到错误:函数调用没有引用。

这是我的代码(请参阅函数 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();
}
4

1 回答 1

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);
        }
    });
}
于 2013-04-18T11:27:57.173 回答