I'm working on a website which requests some data from an API. I'm requesting quite a lot of data so I'm using a template string.
The template string gets parsed correctly but inside the json it messes up. It randomly for some of the numbers adds a "." at the end of the number.
e.g. "http://logs.tf/json/2223521" => "http://logs.tf/json/2223521."
Something to note is that I'm using async: false
function myTest() {
for (Id =2223535; Id >= 2223500; Id--) {
console.log(Id, `http://logs.tf/json/${Id}`);//returns the proper value
$.getJSON(`http://logs.tf/json/${Id}`, function (idData) { //sometimes adds a dot to the url
console.log("success");
});
}
}
E.g what I get from the console(for myTest()):
2223523 "http://logs.tf/json/2223523"
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://logs.tf/json/2223523. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)
2223522 "http://logs.tf/json/2223522"
success
2223521 "http://logs.tf/json/2223521"
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://logs.tf/json/2223521. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Okay so I think I figured it out. It had something to do with the api service I was making the Api request to if I do too many requests I get the error from above.
If I add some arbitrary calculations such as "let number = 452^2" the issue disappears since it delays the time between one request and the next one.
It also doesn't mysteriously add a "." to the request that was just there because the error which got spat out used a dot at the end of the sentence.