how to call javascript function from jQuery ajax? -
i have jquery ajax call results server, , in success, code should call javascript function not in jquery region code, got error in firebug: call of function doesnt have reference.
here code (see ajax call in function addgmarker):
function test1234(res) { preinfo = res; popupcontenthtml = devicemoreinfo_callback_forgoogle(preinfo); var sum = '<p>please, select <b>[sensors reading list]</b> tab view vehcile sensors reading, , select <b>[device communication commands]</b> tab send commands 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 , 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(); }
it's difficult analyse without exact error message, here's 1 thing might help.
the jquery ajax success function gets 3 arguments:
success
type: function( plainobject data, string textstatus, jqxhr jqxhr )`
i suppose msg.d not defined. try rewriting code this:
success: function (data, textstatus, jqxhr) { test1234(data); },
Comments
Post a Comment