How to send large json data (250kb) to mysql database using ajax javascript php

Viewed 132
function saveProjectAjax(docsId, content) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        localStorage.setItem('upadateContent',JSON.stringify(content));
        if (this.readyState == 4 && this.status == 200) {
        }
    };

    xmlhttp.open("GET", "addProjectDetailBase.php?cu=true&pid=" + docsId+"&content="+encodeURIComponent(content), true);
    xmlhttp.send();
}

I want send my content (json) data from function which is large as of 250 kb through content parameter of my function

1 Answers

I agree with what @Magnus Eriksson said above. I will use POST instead of GET. Then I would use a key | value paired object and convert into a JSON string and send over to the server via 'POST'.

Here is an example below,

var xhr = new XMLHttpRequest();
var url = 'addProjectDetailBase.php'
xhr.open("POST", url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
    value: value
}));

Hope this helps,

Cheers.

Related