<bdo id='pzaKp'></bdo><ul id='pzaKp'></ul>
<tfoot id='pzaKp'></tfoot>

  • <small id='pzaKp'></small><noframes id='pzaKp'>

  • <i id='pzaKp'><tr id='pzaKp'><dt id='pzaKp'><q id='pzaKp'><span id='pzaKp'><b id='pzaKp'><form id='pzaKp'><ins id='pzaKp'></ins><ul id='pzaKp'></ul><sub id='pzaKp'></sub></form><legend id='pzaKp'></legend><bdo id='pzaKp'><pre id='pzaKp'><center id='pzaKp'></center></pre></bdo></b><th id='pzaKp'></th></span></q></dt></tr></i><div id='pzaKp'><tfoot id='pzaKp'></tfoot><dl id='pzaKp'><fieldset id='pzaKp'></fieldset></dl></div>
  • <legend id='pzaKp'><style id='pzaKp'><dir id='pzaKp'><q id='pzaKp'></q></dir></style></legend>

        从 ajax 调用返回一个值到父函数

        Return a value from an ajax call to parent function(从 ajax 调用返回一个值到父函数)
      1. <i id='ynIyR'><tr id='ynIyR'><dt id='ynIyR'><q id='ynIyR'><span id='ynIyR'><b id='ynIyR'><form id='ynIyR'><ins id='ynIyR'></ins><ul id='ynIyR'></ul><sub id='ynIyR'></sub></form><legend id='ynIyR'></legend><bdo id='ynIyR'><pre id='ynIyR'><center id='ynIyR'></center></pre></bdo></b><th id='ynIyR'></th></span></q></dt></tr></i><div id='ynIyR'><tfoot id='ynIyR'></tfoot><dl id='ynIyR'><fieldset id='ynIyR'></fieldset></dl></div>

            <small id='ynIyR'></small><noframes id='ynIyR'>

            <legend id='ynIyR'><style id='ynIyR'><dir id='ynIyR'><q id='ynIyR'></q></dir></style></legend>

              <tbody id='ynIyR'></tbody>
                • <bdo id='ynIyR'></bdo><ul id='ynIyR'></ul>
                  <tfoot id='ynIyR'></tfoot>

                • 本文介绍了从 ajax 调用返回一个值到父函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个函数,我需要返回一个通过 ajax 调用获得的 url.

                  I have a function where I need to return a url that I am getting via an ajax call.

                  var heatmap = new google.maps.ImageMapType({
                      getTileUrl: function(coord, zoom) {
                          var tileURL;
                          $.get('getimage.php', { zoom: zoom, x: coord.x, y: coord.y }, function(data) {
                              if(data.status) { tileURL=data.image; }
                          }, "json");
                          return "tileURL";
                      },
                         tileSize: new google.maps.Size(256, 256),
                         opacity:0.55,
                         isPng: true
                  });
                  

                  显然,ajax 调用是异步的,所以我理解为什么上面的代码会返回未定义的 tileURL.我知道一般人们使用回调函数来解决这个问题,但我不知道如何让回调返回父函数的值.我正在使用谷歌地图 API,所以我真的没有任何灵活性来改变它的工作方式.

                  Obviously, the ajax call is asynchronous so I understand why the above code will return tileURL as undefined. I know in general people use callback functions to solve this issue, but I don't know how to get a call back to RETURN a value to the parent function. I'm working with the google maps API, so I don't really have any flexibility to change how that works.

                  推荐答案

                  因为 Ajax 请求是异步的,所以你唯一的选择就是使用回调.如果您可以向父"(实际上是调用")函数返回一个值,那么请求就不会是异步的;它会阻止调用函数.此外,无法从该函数的闭包中获取对调用函数的引用.(即,您不能 return 到调用堆栈中更高的函数).

                  Because the Ajax request is asynchronous, your only option is to use a callback. If you could return a value to the "parent" (really, "calling") function, then the request wouldn't be asynchronous; it would block the calling function. Also, there is no way to get a reference to the calling function from within a closure in that function. (i.e., you can't return to a function higher up in the call stack).

                  这篇关于从 ajax 调用返回一个值到父函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)

                      <small id='S0ad9'></small><noframes id='S0ad9'>

                        <tbody id='S0ad9'></tbody>

                      <legend id='S0ad9'><style id='S0ad9'><dir id='S0ad9'><q id='S0ad9'></q></dir></style></legend>
                      • <bdo id='S0ad9'></bdo><ul id='S0ad9'></ul>
                        • <i id='S0ad9'><tr id='S0ad9'><dt id='S0ad9'><q id='S0ad9'><span id='S0ad9'><b id='S0ad9'><form id='S0ad9'><ins id='S0ad9'></ins><ul id='S0ad9'></ul><sub id='S0ad9'></sub></form><legend id='S0ad9'></legend><bdo id='S0ad9'><pre id='S0ad9'><center id='S0ad9'></center></pre></bdo></b><th id='S0ad9'></th></span></q></dt></tr></i><div id='S0ad9'><tfoot id='S0ad9'></tfoot><dl id='S0ad9'><fieldset id='S0ad9'></fieldset></dl></div>
                          <tfoot id='S0ad9'></tfoot>