简体   繁体   中英

Sending big data to server, Cross-Domain

I'm trying to send chunks of data from many different servers my app is on, to mine.
Using some dummy image source, passing my data as a GET query. ( img.gif?aaa=xxx&bb=yyy... )
the Query is many times too long and gets cut.

is there some better way for me to send the data cross-browser?

It would be the best if you used POST method when sending the data.

 var msgSender = new ActiveXObject("Microsoft.XMLHTTP"); 
 msgSender.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 msgSender.setRequestHeader("Encoding", "Windows-1257")     
 msgSender.open("POST", "http://yourderver/page" ,true);
 msgSender.onreadystatechange = function(){...};
 var msg = "your very long message goes here";

 //preparing post data
 var strToSend = "someotherarg=somevalue" + username;
     strToSend+= "&msg=" + msg;
 strToSend = escape(strToSend);
 msgSender.send(strToSend);

The solution is even easier, if you use jQuery - just call $.post() method: http://docs.jquery.com/Ajax/jQuery.post

EDIT: However, this will not work cross-domain, unless you specify 'Access-Control' headers on your server and the clients have modern enouhg browsers (FireFox 3.5+ etc)

So, another solution is to include a hidden IFRAME in your page (the page lives on your server then) which contains a form and you call Submit() of that form to POST the data.

拆分您的有效负载(例如,以1024字节为单位),然后使用多个GET请求进行发送。

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