Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 472
Nanhe Maurya Avatar asked Jun 28 '26 16:06

Nanhe Maurya


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.

like image 169
Anjana Silva Avatar answered Jul 01 '26 06:07

Anjana Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!