this JS code will send selected text to server
Issue #313
duplicate
Originally reported on Google Code with ID 313
/*this JS code will send selected text to server with POST method: var query = 'txt='+txt*/
document.onmouseup = StartReq;
var req = Create(); // creating reqest
var handleFile = 'capture.php'; //request will be sent to this file
text_for_sending = document.getSelection();
function Create()
{
if(navigator.appName == "Microsoft Internet Explorer")
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
req = new XMLHttpRequest();
}
return req;
}
function Request(query) //function for reqest setup and sending
{
req.open('post' /*request type*/, handleFile , true /*async request*/ );
req.onreadystatechange = Redraw;
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
req.send(query);
}
function StartReq()
{
var radios = document.getElementsByName("switch");
if(radios[0].checked)
{
//encodeURIComponent need when user will select symbols like &%'/ ...
var txt = encodeURIComponent(text_for_sending);
var query = 'txt='+txt;
Request(query) ;
}
}
//////////////////////////////////////////////////////////////////////////////////
function Redraw()
{
//while request sending back, DIV will show 'loading.gif '
var a = req.readyState;
if( a == 4 )
{
var b = req.responseText;
document.getElementById('answer').innerHTML ='<p><h2>Result </h2></p>
'+ b;
}
else
{
document.getElementById('answer').innerHTML = '<p><h2>Result </h2></p><img
src="loading.gif" />';
}
}
Reported by 1invaderzim1
on 2014-12-09 21:12:54
Comments (1)
-
repo owner - Log in to comment
Reported by
oasychev
on 2015-01-23 13:50:39 - Status changed:Duplicate
- Merged into: #322