How to return data from ajax request to php function?

Good evening!

Have a wordpres website + woocommerce.
Write a plugin to calculate shipping cost via the api.

The system is this:
On the checkout page in the city field enter the city name to the field connected to the autocomplete library that works from the same service and pulls in a hidden field code of the city.

Next is using php sends a request to the service, where one of the options city code and us returns shipping cost etc.

The problem is that city code that returns the ajax is not available in php functions.

Task:
How to access received ajax'om data in php or at least how to keep session in woocommerce.
( In the session where woocommerce stores the values for populated fields in this order )
June 14th 19 at 20:51
1 answer
June 14th 19 at 20:53
1) why not make a second ajax request and pass the data to php?
2) why not take a hidden field in the form and pass to php using sumbit? accordingly, the desired field within the script to catch the $_REQUEST'e

Find more questions by tags AJAXPHPWooCommerce