Getting “Object not defined” even when it's loaded before the current script
I have two JS files. One defines a const object called WebRequest and the other uses the WebRequest object.
The file with WebRequest are loaded before the file that uses the object, but I get:
ReferenceError: WebRequest is not defined
Html:
<script crossorigin="anonymous" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" src="https://code.jquery.com/jquery-3.4.1.js" type="application/JAVASCRIPT"></script>
- <script src="/SCRIPT/WebRequest.js" type="application/JAVASCRIPT"></script>
- <script src="/SCRIPT/Identity.Index.js" type="application/JAVASCRIPT"></script>
WebRequest.js:
$(document).ready(() => {
class RequestResult {
constructor(response) {
this.resp = response;
}
response
() {
return this.resp;
}
success
() {
return this.resp.ok;
}
status
() {
return this.resp.status;
}
statusText
() {
return this.resp.statusText;
}
}
const WebRequest = async (controller = "API", action, query = {}, data = {}, method = RequestMethods.POST, mode = RequestModes.SameOrigin, creds = RequestCredentials.SameOrigin, headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}) => {
...
};
});
Identity.Index.js:
$(document).ready(() => {
var _searchBox = $("#searchBox"); var _searchTimeout = null;
_searchBox
.keyup(() => { clearTimeout(_searchTimeout); _searchTimeout = setTimeout(doSearch, 500); });
$
(".search-submit").click(doSearch); $(".result-wrap > .close-wrap > .icon").click(() => { $(".result-wrap").hide(); _searchBox.val(""); _searchBox.focus(); });
async function doSearch() { var str = _searchBox.val();
if (str.length > 0) { $(".search-no-found").hide(); $(".working").show(); $(".search-result").hide(); $(".site-wrap").hide();
var result = await WebRequest("Identity", "Search", null, { text: str }); } else { $(".result-wrap").hide(); } } });
Any ideas??
--------------
Just so we're clear - you need a hero?