Задача состоит в том, чтобы передать серверу POST запрос через Ajax. Но проблема возникает если передавать строку с амперсандом. Она обрезается от него. Не могу справиться.
Скрипт:
function XmlHttp()
{
var xmlhttp;
try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{
try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
catch (E) {xmlhttp = false;}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function ajax(param)
{
if (window.XMLHttpRequest) req = new XmlHttp();
method=(!param.method ? "POST" : param.method.toUpperCase());
if(method=="GET")
{
send=null;
param.url=param.url+"&ajax=true";
}
else
{
send="";
for (var i in param.data) send+= i+"="+param.data[i]+"&";
send=send+"ajax=true";
}
req.open(method, param.url, true);
if(param.statbox)document.getElementById(param.statbox).innerHTML = '<img src="/images/wait.gif" width="100">';
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(send);
req.onreadystatechange = function()
{
if (req.readyState == 4 && req.status == 200) //если ответ положительный
{
if(param.success)param.success(req.responseText);
}
}
}
Форма:
<input type="text" maxlength="100" id="url" name="url" /> <a href="javascript:return false;" onclick="off(); ajax({url:'/serv.php',statbox:'status2',method:'POST',data:{container:document.getElementById('url').value,},success:function(data){document.getElementById('status2').innerHTML=data;}}); return false;"><span>Отправить</span></a>
Могут ли быть потенциальные проблемы с другими символами? Через форму передается ссылка.