Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I post large data to the server?

I have to send the XML from the client side to the server side.

The method adopted by me was that:

First the xml is converted to string in the javascript and then post as a uri

var url = '/perl/set_zorder_xml.cgi'+'?'+xmlString+'&'+location+'&'+'nocache='+randomnumber;

xml string is the string that contains the xml in string form.

The post function looks like this:

if (window.XMLHttpRequest) {
            req_anno = new XMLHttpRequest();
            req_anno.open("POST", url, false);
            req_anno.send();
            }

The problem is that when my xml string is very large then html 414 error occurs i.e url too large. Is there any way out, Javascript and perl is used

like image 664
Zeeshan Avatar asked Oct 04 '22 12:10

Zeeshan


1 Answers

Even though you're doing a POST request, you're still sending the data in the querystring of the URL. Instead you should move the data to be sent as POST data, and remove it from the URL.

req_anno.open("POST", '/perl/set_zorder_xml.cgi', false);
req_anno.send('xml=' + encodeURIComponent(xmlString));

The XHR .send() method accepts the string to be sent as the request body (ie POST data).

like image 197
MrCode Avatar answered Oct 07 '22 20:10

MrCode