**文書の過去の版を表示しています。**
20211008
ローカルでjQueryを使う
jQueryの仕様変更の影響を受けないように、ローカルにjQueryのスクリプトをダウンロードし、使用したい。
まずhttps://jquery.com/download/からhttps://code.jquery.com/jquery-3.6.0.jsをダウンロードし、public/javascrptディレクトリに配置する。
jQueryを使用したいHTMLファイル上で以下のscriptタグで読み込む。
<script src='javascript/jquery-3.6.0.js'></script>
参考にしたサイト:https://techacademy.jp/magazine/9482
Ajaxでキャプチャエリア内のサンプル情報を非同期的にやり取りする
マップの移動・拡大・縮小のイベント発生時にAjaxでサーバに非同期的にキャプチャエリア内のサンプル情報を送信する。
index.ejs
$.ajax({
url: './',
type: 'POST',
cache: false,
dataType: 'json',
data: {capturedSampleList: capturedSampleList},
})
.done(function(response){
console.log("success");
});
index.js
router.post('/', function (req, res) {
console.log("Test");
res.send("Test");
});
responseを返してあげないとエラーになるので注意