Getting 403 errors on some asynchronous ajax get requests, only on test server

I have a function that iterates throw a bunch of input elements, runs a query to check something in the database for each, and then alters a bit of CSS based on the results. It has been working for a while now but suddenly has problems. The problem is only when it's running on the test server. If I debug in VS it works fine. Additionally, if I step through with breakpoints in the browser it works fine. It runs asynchronously so I suspect that's causing the problem somehow. Here's some code:

function highlight(elements) {
elements = elements || $(":input[id$='SPQ']");
$.each(elements, function (key, value) {
    var data;
        data = {
                fieldName: $(value).attr('id'),
                pkValue: $("#" + form + " #PkValue").val()         
        };
    

    jsonGetHelperAsync("/spq/Check", data, function (results) {
        if (results.wasSuccess) {
            if (results.isChanged > 0) {
                $(value).css({ 'color': 'red' });
            }
        } else displayMessage("Error!");
    });
});
}

function jsonGetHelperAsync(url, data, success) {
$.ajax({
    dataType: "json",
    type: "GET",
    data: data,
    url: url,
    success: function(results) {
        success(results);
    },
    async: true,
    global: false
});
}

The error says the JsonGetHelperAsync is getting a 403. It will get the error about 10 times fewer then there are fields on the page. There is an item that is supposed to turn red if conditions are met. If the item is near the top of the page it works, near the bottom it doesn't. It really seems like some code is completing early and breaking things, but I can't figure it out. I tried lots of async/await and Promise stuff but it all breaks the same way, even if it works when I Debug.

Anyone know what I'm missing? Thanks.



Read more here: https://stackoverflow.com/questions/67928961/getting-403-errors-on-some-asynchronous-ajax-get-requests-only-on-test-server

Content Attribution

This content was originally published by erosebe at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: