How js dynamically introduces script, and then require the js that should be introduced

problem description

I need to dynamically introduce a js, < script type= "text/javascript" src= " http://192.168.1.189:6789/arcgis_js_api/library/3.24/init.js"></script>
now needs to dynamically concatenate src addresses from the background, introducing easy maintenance that is not written as fixed

related codes

I tried to introduce js like this, but the console reported an error Uncaught SyntaxError: Unexpected token when calling initGisMap (). If I introduce this script map statically into head directly, it will display normally. I would like to ask whether this is correct, or are there any other ideas to achieve such a function

$(function() {
  //htmldom
  var theHead = document.getElementsByTagName("head").item(0);
  //dom
  var myScript = document.createElement("script");
  myScript.src = "http://172.42.1.146:6789/arcgis_js_api/library/3.24/3.24/init.js";    
  myScript.type = "text/javascript";  
  myScript.defer = true;              
  myScript.onload = function() {
    initGisMap()
  }
  theHead.appendChild(myScript);      
});

function initGisMap(){
  require(["esri/map",
      "esri/tasks/FindTask",
      "esri/tasks/FindParameters",
      "extras/ClusterLayer",
      "dojo/domReady!"
    ],
    function (Map, FindTask, FindParameters, ClusterLayer) {
      var map;
      map = new Map("map", {
        center: [112.28888, 31.38888], // 
        slider: false,
        zoom: 0,
        scale: 5000000, //
        //
        maxScale: 5000,
        //
        minScale: 3000000,
        isPanArrows: true,
        logo: false,
      });
      //http://192.168.1.189:6080/arcgis/rest/services/hubei10/MapServer GIS
      var mapServiceURL = "http://172.42.1.146:6080/arcgis/rest/services/HBGSOMP/MapServer" //GIS
      var layer = new esri.layers.ArcGISDynamicMapServiceLayer(mapServiceURL)
      map.addLayer(layer);
      map.on("load", mapLoaded);
      //  
      map.on("mouse-wheel", function (o) {
        // 
        var scale = Math.ceil(map.getScale())
        var minScale = map.getMinScale()
        var maxScale = map.getMaxScale()
        if (scale == minScale) {
          map.setScale(minScale)
          map.setZoom(0)
          map.centerAt([112.28888, 31.38888])

        }
      })

      function mapLoaded() {
        //resize
        if (map && map.map) {
          map.map.resize(true);
          map.map.reposition();
        }
        // mapwindow
        window.map = map
        // 
        start()
      }

      this.getClusterLayer = function (data) {
        return new ClusterLayer(data)
      }
    })
May.04,2021

if you have a template engine, you can just use it? If you do not use the interface to return the address of that js, then introduce


with $.getScript
theHead.appendChild(myScript);   

this and the above code are written to $(function () {}) try outside

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e35b1d-26893.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e35b1d-26893.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?