【问题标题】:How can an XMLHttpRequest be used to send JSON data and which method is better to use from GET or POST?如何使用 XMLHttpRequest 发送 JSON 数据以及从 GET 或 POST 中使用哪种方法更好?
【发布时间】:2020-04-27 10:36:14
【问题描述】:

GETPost 中的哪种方法更适合用于下面显示的代码,它们的优点是什么? 该代码应该根据用户的位置返回数据。

  function findPark (latitude,longitude) {
  var myReq = new XMLHttpRequest();
  var serviceURL = "https://www.ratemyPlace.prg/getRating?";
  serviceURL += "lat=" + latitude;
  serviceURL += "&lng=" + longitude;
  myReq.addEventListener("load", myListener);
  myReq.open("GET", serviceURL);
  myReq.send();

【问题讨论】:

    标签: javascript post get xmlhttprequest


    【解决方案1】:

    使用 GET。

    • 这看起来像是一个没有副作用的只读操作
    • 它没有消息正文

    另请参阅:What is the difference between POST and GET?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2016-12-05
      • 2010-10-10
      相关资源
      最近更新 更多