简体   繁体   English

单击按钮多次获取请求

[英]multiple get request on button click

Is it possible to integrate within a click event multiple get request? 是否可以在一个点击事件中集成多个获取请求? I am getting adress data from a database. 我正在从数据库中获取地址数据。 As a second step I extracted the coordinates and send them back to the server. 第二步,我提取了坐标并将其发送回服务器。 I want to pass the points which are within a buffer to Javascript. 我想将缓冲区内的点传递给Javascript。

$("#ok").click( function(event) {


$.get(url + 'c=' + text, function(data) {

   result1 = data;


$.ajax({
   url: my_url,
   type: "POST",
   data: my_data
  });

 });

 $.get(url, function(data) {

    result2 = data;
    console.log("yes");

   });

  });

Using the done . done When one request is ready and processed, let's execute the other using done . 准备好一个请求并进行处理后,让我们使用done执行另一个请求。 See below. 见下文。 Also I've hoisted the x and y up to make them available throughout the block. 另外,我还提升了xy使其在整个块中可用。

$("#ok").click( function(event) {

     var text = $('#st').val();
     var x,y;
     $.get('localhost:5000/adress?' + 'c=' + text, function(data) {

          mydata2 = data; //JSON.parse is not needed

          for (var i = 0; i <mydata2.length; i++){
          y = mydata2[i][1];
          x = mydata2[i][0];

          l = L.marker([y, x]).addTo(map);
      }).done(function(){
         $.ajax({
            url: 'localhost:5000/long_lat',
            type: "POST",
            data: {"x": x, "y": y}
      }).done(function(){

          $.get('localhost:5000/long_lat', function(data) {

          mydata3 = (data);
          console.log("yes");

         });
      });
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM