Hello, I am writing code on Vanilla Js. The bottom line is that I get requests from the server using jsonp, and sometimes for some reason unknown to me, 404 arrives. In general, I need to repeat the request if suddenly 404 flies out. Thank you in advance for the answer!
1 answer
It would be nice to see your code.
It is not possible to know the status of the response if it is loaded via the script tag.
The only thing that can be done is to understand that the download is unsuccessful.
At the script , img , link and iframe tags you can set callbacks on onload and onerror :
let jq = document.createElement("SCRIPT"); jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"; document.body.appendChild(jq); jq.onload = _ => console.info("jQuery успешно загружен!"); jq.onerror = _ => console.info("Ошибка с jQuery!"); let _404 = document.createElement("SCRIPT"); _404.src = "https://example.com/_NotFoundScript.js"; document.body.appendChild(_404); _404.onload = _ => console.info("_404 успешно загружен о_О!"); _404.onerror = _ => console.info("Ошибка с _404!"); In the body of the error callback just run the repeat request.
|