I got base64 encoding on the page and wanted to interact with the background through Ajax, but all the + numbers of the data obtained in the background were changed to spaces and checked.
When Using ajax to pass data, data is usually organized into data = "var1 = ABC & var2 = Def ". When the plus sign (+) or connector (&) exists in the data, some data is lost when the server receives the data.
It is not difficult to analyze the Ajax Data Transmission Format and JavaScript Syntax:
1. "+": javascript is parsed as a string connector, so "+" is lost when the server receives data.
2. "&": javascript is parsed as a variable connector, so data after the & symbol is received by the server is lost.
The solution is also quite simple. You only need to encode + and & Symbol:
// use post to send
function dorequestusingpost ()
{< br> createxmlhttprequest ();
var retcode = document. getelementbyid ("retcode "). value;
var DATA = document. getelementbyid ("data "). value;
DATA = data. replace (// +/g, "% 2B");
DATA = data. replace (// &/g, "% 26");
var querystring = "retcode =" + retcode + "& Data =" + data;
var url = "backsealservlet"; // use a URL to send a value to the background.
// XMLHTTP. open ("Post", URL, true);
XMLHTTP. open ("Post", URL, false);
XMLHTTP. onreadystatechange = handlestatechange;
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded");
XMLHTTP. send (querystring);
// alert ("ended" + retcode);
}