+ -
当前位置:首页 → 问答吧 → jquery中Ajax定时去后头获取数据问题

jquery中Ajax定时去后头获取数据问题

时间:2011-05-07

来源:互联网

JScript code
function loadGPSDataByAjax() {
            $.ajax({
                type: "get",
                url: "GetMapVehicleGpsInfoByAjax.ashx",
                contentType: "application/xml; charset=utf-8",
                dataType: "xml",
                beforeSend: function(XMLHttpRequest) { $("#loading").show(); },
                complete: function(XMLHttpRequest, textStatus) {$("#loading").hide();},
                success: function(data) {
                    //alert("ddd");
                    $(data).find("vehicle").each(function(i) {
                        var key = $(this).attr("vinNum");
                        var value = $(this).find("lngLat").text();
                        alert(value);
                        gpsMap.put(key, value);
                     });
                    window.setTimeout("loadGPSDataByAjax();", 4000);
                },
                error: function(err) {
                    ajaxIsLoading = false;
                    alert("读取数据出错,看是否有GPS信息号,如果存在则请联系系统管理员");
                }
            });
        }


各位大侠帮忙解决一下,我是在.NET中用jQuery的。页面首次加载的时候可以从后台获取到数据,我在后台代码设了断点也可以拦截到,但是在定时4秒钟后再次去后台获取数据,就读不到后台的数据,断点也没反应。

作者: duqing86   发布时间: 2011-05-07

可能IE换成问题,cache设置为false或者给url加时间戳防止缓存

 $.ajax({
  type: "get",
  cache:false,
  url: "GetMapVehicleGpsInfoByAjax.ashx",
  contentType: "application/xml; charset=utf-8",

或者

JScript code
url: "GetMapVehicleGpsInfoByAjax.ashx?_dc="+new Date().getTime(),

作者: showbo   发布时间: 2011-05-07

热门下载

更多