CORS错误随机发生

So I'm working on sending data to express using AJAX, the problem is that I have two different outcomes even if sending the exact same data each time:

  1. I get a CORS error
  2. The process go through with no errors, but server says that the data is undefined

Why is the CORS error only occurring sometimes? Why (when CORS doesn't fail) does the server say that the data is undefined?

Code for question #2:

Client side:

document.getElementById('depositButton').onclick = function() {
    var steamid = getSteamID();
    if(steamid == "") {
        alert("Something went horribly wrong, please inform us about this issue by DM'ing us at https://twitter.com/csgobeararms");
    }

    console.log(JSON.stringify({arr:items}));
    $.ajax({
        type: 'POST',
        url: 'http://localhost:1337/deposit?steamid=' + steamid,
        data: {arr:items},
        success: function(data) {
            console.log("Tradeoffer has been sent");
        },
        error: function(data) {
            alert("Failed to call bot, please inform us about this issue by DM'ing us at https://twitter.com/csgobeararms (Additional info in console)");
            console.log("Failed to call bot, please inform us about this issue by DM'ing us at https://twitter.com/csgobeararms");
            console.log("This is what we know: ");
            console.log(data);
        }
    });
}

function getSteamID() {
    var cookie = getCookie("steamid");
    if(cookie != "") {
        return cookie;
    } else {
        return "";
    }
}

function getCookie(cookie) {
    var name = cookie + "=";
    var decoded = decodeURIComponent(document.cookie);
    var ca = decoded.split(';');
    for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while(c.charAt(0) == ' ') {
            c = c.substring(1);
        }

        if(c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

Server side:

var bodyParser = require('body-parser');
var express = require('express');
var app = express();
app.use(bodyParser.json());

app.use(function(err, req, res, next) {
    console.error(err.stack);
    console.log("ezpzlmnsqz")
    res.status(500).send("Something went horribly wrong!");
});

app.post('/deposit', function(req, res) {
    console.log('Deposit request recieved, info:');
    console.log('STEAM ID: ' + req.query.steamid);
    console.log('ITEMS: ' + req.params.arr);
    res.status(200).send('Success');
});

app.listen(1337);