javascriptjquerycesiumjssandcastle

CESIUM ERROR "ReferenceError: $ is not defined " (writing in SANDCASTLE)


$.ajax({
  type: "GET",
  dataType: "json",
  url: "https://reqres.in/api/unknown/2",
  success: function(data){
    console.log(data)
  }
});

i tried insesrt:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

but cesium not works like ordinary platfroms


Solution

  • Cesium's "Sandcastle" test environment does not include a means to include JQuery. Instead, you can use Cesium's own helper functions for things like this, such as Cesium.Resource.fetchJson.

    For example: Live Sandcastle Demo

    var viewer = new Cesium.Viewer("cesiumContainer");
    
    Cesium.Resource.fetchJson({
      url: "https://reqres.in/api/unknown/2"
    }).then(data => {
      console.log(JSON.stringify(data, null, '    '));
    });