You forgot to explicitly set to Content-type
header, which is necessary when doing POST requests.
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
Also, do not forget to use encodeURIComponent
to properly encode your parameters, e.g.:
var params = "var=" + encodeURIComponent("1");
(in this particular example, it's not necessary, but when using special characters like +
things will go horribly wrong if you don't encode the parameter text).
Update – you should also replace all instances of %20
with +
, like
var params = params.replace(/%20/g, '+');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…