如何从jQueryAjax调用javascript函数?
我使用jQuery ajax调用从服务器获取结果,如果调用成功,代码应该调用不在jQuery区域代码中的javascript函数,因此我在firebug中遇到错误:函数的调用没有引用 下面是我的代码(请参阅函数addGMarker中的ajax调用):如何从jQueryAjax调用javascript函数?,javascript,jquery,google-maps-api-2,Javascript,Jquery,Google Maps Api 2,我使用jQuery ajax调用从服务器获取结果,如果调用成功,代码应该调用不在jQuery区域代码中的javascript函数,因此我在firebug中遇到错误:函数的调用没有引用 下面是我的代码(请参阅函数addGMarker中的ajax调用): 功能测试1234(res){ PreInfo=res; popupContentHTML=deviceMoreinfo\u callBack\u ForGoogle(PreInfo); var sum='请选择[Sensors Reading Li
功能测试1234(res){
PreInfo=res;
popupContentHTML=deviceMoreinfo\u callBack\u ForGoogle(PreInfo);
var sum='请选择[Sensors Reading List]选项卡查看车辆文件传感器读数,并选择[Device Communication Commands]选项卡发送设备命令:
;
变量选项卡=[
新的MaxContentTab(“传感器读取列表”,maxContentDiv),
新的MaxContentTab(“设备通信命令”,maxContentDivForCommands)];
this.openMaxContentTabsHtml(map、popupContentHTML、sum、tabs,{maxTitle:“传感器和功能”});
var iw=map.getTabbedMaxContent();
iw.id=this.id;
addListener(iw,'selecttab',函数(tab){
var node=tab.getContentNode();
开关(tab.getLabel()){
案例“传感器读数列表”:
maxContentDiv.innerHTML='Loading…';
//GetSensorsReading(this.id,ClientID,“En”,GetSensorsReading\u回调);
jQuery.ajax({
类型:“POST”,
url:“../../../DeviceManagerajax.asmx/GetSensorsReading”,
数据:“{Device_ID:'”+this.ID+”,ClientID:“+ClientID+”,第{Device_ID:'En'}页”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
超时:70000,
成功:功能(msg){
var res=msg.d;
GetSensorsReading_回调(res);
},
错误:函数(xhr、状态、错误抛出){
警报(“发生错误,+ERRORSHORN”);
}
});
打破
案例“设备通信命令”:
maxContentDivForCommands.innerHTML='Loading…';
//GetContorLableSensors(this.id,ClientID,“En”,GetContorLableSensors\u回调);
jQuery.ajax({
类型:“POST”,
url:“../../../DevicesManagerAjax.asmx/GetContorolableSensors”,
数据:“{Device_ID:'”+this.ID+”,ClientID:“+ClientID+”,第{Device_ID:'En'}页”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
超时:70000,
成功:功能(msg){
var res=msg.d;
GetContolableSensors\u回调(res);
},
错误:函数(xhr、状态、错误抛出){
警报(“发生错误,+ERRORSHORN”);
}
});
打破
}
});
}
功能添加标记器(ID、点、标记图标){
图标=新GIcon(G_默认图标);
如果(_IconClientID==“0”){
如果(标记图标==“蓝色”){
if(ID==FollowVechicleID){
icon.image=“../../Images/Icons/”+\u Follow\u图标;
}
否则{
icon.image=“../../Images/Icons/”+_Normal_图标;
}
if(ID==FollowVechicleID){
ShowLastThreePositions();
}
}
否则{
icon.image=“../../Images/Icons/”+\u速度\u图标;
}
}
否则{
如果(标记图标==“蓝色”){
if(ID==FollowVechicleID){
icon.image=“../../Images/Icons/ClientsIcons/”+\u Follow\u图标;
}
否则{
icon.image=“../../Images/Icons/ClientsIcons/”+\u Normal\u icon;
}
}
else if(标记图标==“红色”){
icon.image=“../../Images/Icons/ClientsIcons/”+\u速度\u图标;
}
}
icon.iconSize=新的GSize(32,32);
icon.dragCrossSize=新的GSize(0,0);
icon.shadowSize=新的GSize(32,32);
icon.iconAnchor=新的GPoint(5,5);
标记=新的GMarker(点、图标);
marker.id=id;
GEvent.addListener(标记“单击”,
函数(){
popupContentHTML=Device\u Option\u forGoogle(this.id);
openInfoWindowHtml(popupContentHTML);
}
);
GEvent.addListener(标记“mouseover”,
函数(){
//PreInfo=getDeviceInfo-ForPopup(this.id,ClientID,“En”);
jQuery.ajax({
类型:“POST”,
url:“../../../DeviceManagerajax.asmx/GetDeviceInfo-ForPopup”,
数据:“{deviceID:'”+this.id+”,IDclient:“+ClientID+”,第页:'En'}”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
超时:70000,
成功:功能(msg){
var res=msg.d;
test1234(res);
},
错误:函数(xhr、状态、错误抛出){
警报(“发生错误,+ERRORSHORN”);
}
});
});
var标记=[];
标记器。推(标记器);
经理添加标记(标记,0);
经理刷新();
ClientPOI.refresh();
POImgr.refresh();
}
这与从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);
}
});
}
您粘贴的代码段是rela
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);
}
});
}