ajaxStop の使い方

jQuery の ajaxStop の使い方です。

次の Node.js のプログラムと同じ処理です。
[Node.js の async/await のサンプル](https://qiita.com/ekzemplaro/items/6ba403b8fab35c7cc5cb)

実行結果
![ajax_stop.png](https://qiita-image-store.s3.amazonaws.com/0/179446/f38d2857-4afe-bc47-5ac2-32de3a4b4d2c.png)


```html:index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" />
<script src="/js/jquery-3.2.1.min.js"></script>
<script src="ajax_stop.js"></script>
<title>Ajax Stop</title>
</head>
<body>
<h2>Ajax Stop</h2>
<div class="contents">contents</div>


<hr />
<div id="outarea_aa">outarea_aa</div>
<div id="outarea_bb">outarea_bb</div>
<div id="outarea_cc">outarea_cc</div>
<div id="outarea_dd">outarea_dd</div>
<div id="outarea_ee">outarea_ee</div>
<div id="outarea_ff">outarea_ff</div>
<div id="outarea_gg">outarea_gg</div>
<div id="outarea_hh">outarea_hh</div>


<hr />
<a href="html_src/">src</a><p />
<hr />
Version: May/06/2018 PM 20:34<br />
</body>
</html>
```

```js:ajax_stop.js
// -----------------------------------------------------------------------
//
//	ajax_stop.js
//
//						May/06/2018
//
// -----------------------------------------------------------------------
jQuery (function ()
{
	jQuery("#outarea_aa").text ("*** ajax_stop.js *** start ***")

	const array_in = [[43.08,141.35],
			[36.56,139.88],
			[35.91,139.66],
			[35.68,139.76],
			[35.16,136.90],
			[34.70,135.50],
			[33.59,130.42],
			[31.56,130.56],
			[26.21,127.68]
			]
	array_aa = []

	for (var it in array_in)
		{
		const pos = array_in[it]

		get_data_proc(pos,array_aa)
		}

	jQuery( document ).ajaxStop(function()
		{
		const str_out = post_proc(array_aa)

		jQuery(".contents").html (str_out)
		})

	jQuery("#outarea_hh").text ("*** ajax_stop.js *** end ***")
})


// -----------------------------------------------------------------------
// [4]:
function get_data_proc(pos,array_aa)
{
	const lat = pos[0]
	const lon = pos[1]

	api_key="***************************************"
	url_aa="https://maps.googleapis.com/maps/api/geocode/json?latlng="
	url=url_aa + lat + "," + lon + "&language=ja&key=" + api_key


	jQuery.get(url,function(res)
		{
		var unit_aa = parser_results(res)

		unit_aa['lat'] = lat
		unit_aa['lon'] = lon
		array_aa.push(unit_aa)
		})

}

// -----------------------------------------------------------------------
// [4-4]:
function parser_results(dict_aa)
{
	var unit_out = {}
	unit_out['city'] = ""
	unit_out['pref'] = ""

	const components = dict_aa['results'][0]['address_components']
	for (var it in components)
		{
		const unit_aa = components[it]
		if (unit_aa['types'][0] == "locality")
			{
			unit_out.city = unit_aa['short_name']
			}
		else if (unit_aa['types'][0] == "administrative_area_level_1")
			{
			unit_out.pref = unit_aa['short_name']
			}
		}

	return unit_out
}

// -----------------------------------------------------------------------
// [8]:
function post_proc(array_aa)
{
	const ncount = array_aa.length

	jQuery("#outarea_bb").text ("ncount = " + ncount)

	var str_out = ""
	array_aa.forEach(function(unit)
	{
	str_out += unit.lat +  " " +  unit.lon
	str_out += " " + unit.city + " " + unit.pref + "<br />"
	})

	return	str_out
}

// -----------------------------------------------------------------------
```