[英]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. 使用一些虚拟图像源,将我的数据作为GET查询传递。 ( img.gif?aaa=xxx&bb=yyy... )
( 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. 如果在发送数据时使用POST方法,那将是最好的。
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 如果使用jQuery,则解决方案甚至更简单-只需调用
$.post()
方法即可: 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) 编辑:但是,这将无法跨域工作,除非您在服务器上指定“ Access-Control”标头,并且客户端具有现代的enouhg浏览器(FireFox 3.5+等)
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. 因此,另一种解决方案是在页面中包含一个隐藏的IFRAME(然后该页面位于您的服务器上),其中包含一个表单,然后调用该表单的Submit()来发布数据。
拆分您的有效负载(例如,以1024字节为单位),然后使用多个GET请求进行发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.