Answer the question
In order to leave comments, you need to log in
How to pass variable from one function to ajax request?
Hello. There are 2 functions.
The first function - fills in the fields (Region, City, Street ...) when selecting some element from the autocomplete list of Google Map Api.
The second function is called when the button is clicked. This is a simple ajax request that contains data from the fields.
From the first function, I need to get a variable with the coordinates of the selected location. And send this variable along with the field data.
Why exactly?
Sometimes it happens that when choosing a place, only 1 field will be filled. Google accurately indicates the place on the map, but does not give out the full address (there is no region, city, or even a street). Therefore, it is not possible to get coordinates on the server side.
UPD:
I did this:
window.coord = place.geometry.location;
Answer the question
In order to leave comments, you need to log in
Just remember these coordinates somewhere (for example, in $("#id").data("value"), and read from the Ajax function.
You can do it in different ways depending on the context. You can make a hidden field and write it down there, you can make this variable available to both functions, in order to do this correctly, read about scopes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question