20211008

20211008

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でサーバに非同期的にキャプチャエリア内のサンプル情報を送信する。

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を返してあげないとエラーになるので注意

  • 20211008.1633681078.txt.gz
  • 最終更新: 2021/10/08 08:17
  • by 133.11.144.10