【问题标题】:My ajax function isnt sending the data我的 ajax 函数没有发送数据
【发布时间】:2015-10-04 04:11:14
【问题描述】:

首先,我使用谷歌地图和我使用 tomcat 我想要做的是,当我点击地图时,我会放置一个标记并 同时 y 发送点的纬度和经度

这是我的代码:

map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    google.maps.event.addListener(map, 'click', function(event)
    {
            placeMarker(event.latLng);
            $.ajax({
                url: 'insertPoint.java',
                type: 'POST',
                data: {lat:latitud, lon:longitud},
                dataType: 'json',
                cache: false
            })
             .done(function(mensaje) {

                 document.write("success");
             })
             .error(function(mensaje) {
                 document.write("error");
             });
    });
    }

但我不知道为什么我总是出错。 如果您需要其他内容,我将编辑帖子并发布你们需要的内容

谢谢

PD:我也尝试将 url 行更改为:

url: 'insertPoint',

【问题讨论】:

  • 您检查浏览器控制台是否有任何错误报告?
  • 就像控制台选项卡一样,您在网络选项卡中看到的内容与您触发的 url 相对...这将回答您的查询。
  • send the lat and long of the point - 你觉得你是怎么做到的? {lat:latitud, lon:longitud} - 什么是纬度和经度?
  • 但我不知道为什么我总是出错而你却说0个错误报告
  • Jaromanda X 因为如果 ajax 不发送信息,我会做一个 document.write,如果它发送它,它会说成功,纬度和经度是变量

标签: javascript jquery ajax google-maps


【解决方案1】:

jQuery promice 没有error 方法。你需要用fail方法监听错误

 .fail(function(error){})

【讨论】:

    【解决方案2】:

    ajax POST 应该以这种格式调用。

       $.ajax({
              url: 'url',
              type: 'post',
              data: {'lat':latitud, 'lon':longitud},
              dataType: 'json',
              cache: false,
              success: function(result){
                  alert('success!');
              },
              failed: function(result){
                  alert('Somethings wrong');
              }
        });
    

    【讨论】:

      猜你喜欢
      • 2022-11-01
      • 2012-03-13
      • 1970-01-01
      • 2014-01-23
      • 2016-10-17
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多