B
B
Baxterok2015-08-14 02:03:03
JavaScript
Baxterok, 2015-08-14 02:03:03

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

2 answer(s)
H
heartdevil, 2015-08-14
@heartdevil

Just remember these coordinates somewhere (for example, in $("#id").data("value"), and read from the Ajax function.

E
Evgeny Elchev, 2015-08-14
@rsi

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 question

Ask a Question

731 491 924 answers to any question