Search code examples
javascriptarraysajaxsend

Send non-editable Array with JSON & Ajax


Is it possible to send non-editable arrays?

What i'm trying to send is:

var items = [];
//console.log(JSON.stringify(items));
allitems = JSON.stringify(items);

[{
    "assetid": "7814010469",
    "classid": "1797256701",
    "instanceid": "0",
    "name_color": "D2D2D2",
    "icon_url": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXU5A1PIYQNqhpOSV-fRPasw8rsUFJ5KBFZv668FFYznarJJjkQ6ovjw4SPlfP3auqEl2oBuJB1j--WoY322QziqkdpZGr3IteLMlhpw4RJCv8",
    "market_hash_name": "Gamma Case"
}]

$.ajax({
    type: "POST",
    async: true,
    url: "jackpot/deposit",
    data: {
        myData: allitems
    },
    success: function(body) {
        toastr["info"]("Success! Our bots are generating your trade. Please wait...", "Inventory");
    },
});

But I want to make it not editable via the console. And send it.


Solution

  • You should be able to use Object.freeze() to prevent the array from being changed. For example:

    var arr = [1, 2, 3];
    Object.freeze(arr);
    arr.push(4); // error