【问题标题】:Send data with $.ajax GET使用 $.ajax GET 发送数据
【发布时间】:2013-07-08 14:22:49
【问题描述】:

我需要通过 get 请求发送数据,但我不想将参数附加到字符串,我想发送一个数据对象。

根据 jQuery 文档,它应该可以工作,在发送请求之前将对象解析为字符串。

但它不起作用。

$.ajax({
    url: $(_this).data('action-service-collect-point'),
    data : {
        lat: position.coords.lat,
        lng: position.coords.lng
        },
    dataType:"json",
    success: function(res){
        ...
        },
    error: function (xhr, ajaxOptions, thrownError)
        {
        ...
        }
    });

只调用url,不带任何参数。

【问题讨论】:

  • 是否定义了position.coords.latposition.coords.lng
  • 另外,您确定网址是您认为的那样吗?假设未知数是正确的,代码看起来很好。另一件事,url 是本地资源还是远程资源?
  • @BillCriswell 该网址是本地网址。是的,定义了 lat 和 lng。
  • 如果取消设置 dataType 会发生什么?您确定服务器正在发送正确的响应标头吗?
  • @BillCriswell 仍在调用不带参数的 url。

标签: jquery ajax parameters get


【解决方案1】:
 function showLocation(location) {

      $.ajax({  
          url: "yourfile",
          data: {
            'lat': location.coords.latitude,
            'lng': location.coords.longitude,
            'alt': location.coords.altitudeAccuracy,
            'date':Date()
          },
          type: 'POST'

      });

     }

例如,在加载页面时运行的函数中插入 ajax

【讨论】:

  • OP 问题是使用GET http 方法发送数据,而不是POST。如果可能,请相应地更改答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-07
  • 1970-01-01
  • 1970-01-01
  • 2017-01-28
  • 1970-01-01
  • 1970-01-01
  • 2014-06-10
相关资源
最近更新 更多