简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM