Returning a value from a Promise

前端 未结 4 1652
猫巷女王i
猫巷女王i 2020-12-31 16:47

I would like to call the Google Maps Geocoding API using a Promise like this:

function makeGeoCodingRequest(address,bounds)
{
    /*
        Input parameters         


        
4条回答
  •  悲&欢浪女
    2020-12-31 17:00

    If you want your code to wait until the asynchronous action is completed before continuing (BAD IDEA - the page will freeze while the request is completing) then add async: false to the ajax request's parameters.

    My recommendation, though, is to have makeGeoCodingRequest return nothing directly - and simply give it an extra argument, requestCallback so that its caller can pass in a function that will be called when the data is available. Call that function, with the resulting data, inside of your promise.then function.

提交回复
热议问题