MirceaP
06-17-2009, 12:24 PM
Hello,
I an a newbye trying to fix an Ajax submit problem.
I am using an Ajax submit form. It works fine except when I submit a post with "&". Posting something with this character brakes down the submit up to that point when the character occurs.
What should I do?
Here is my submit Ajax code.
Thank you,
Mircea
<script type="text/javascript">
var fieldname = 'postrowbody';
var xmlHttp = http_object();
function get(f)
{
var param = elem = '';
for(var s = 0; s < f.elements.length; s++)
{
elem = f.elements[s];
if(param != '')
{
param += '&';
}
param += elem.name + '=' + elem.value;
}
document.getElementById(fieldname).innerHTML += "<div id='load' class='preloader'><img src='/tabs/loading.gif' /><p>Requesting content...</p></div></div>";
xmlHttp = http_object();
xmlHttp.onreadystatechange = handle_return;
xmlHttp.open("POST", '{S_AJAX_ACTION}', true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send(param);
//clear the message site
document.postform.message.value = '';
}
function handle_return()
{
if (xmlHttp.readyState == 4)
{
var load = document.getElementById('load');
load.parentNode.removeChild(load);
document.getElementById(fieldname).innerHTML += xmlHttp.responseText;
document.postform.reset();
}
}
function http_object()
{
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
</script>
I an a newbye trying to fix an Ajax submit problem.
I am using an Ajax submit form. It works fine except when I submit a post with "&". Posting something with this character brakes down the submit up to that point when the character occurs.
What should I do?
Here is my submit Ajax code.
Thank you,
Mircea
<script type="text/javascript">
var fieldname = 'postrowbody';
var xmlHttp = http_object();
function get(f)
{
var param = elem = '';
for(var s = 0; s < f.elements.length; s++)
{
elem = f.elements[s];
if(param != '')
{
param += '&';
}
param += elem.name + '=' + elem.value;
}
document.getElementById(fieldname).innerHTML += "<div id='load' class='preloader'><img src='/tabs/loading.gif' /><p>Requesting content...</p></div></div>";
xmlHttp = http_object();
xmlHttp.onreadystatechange = handle_return;
xmlHttp.open("POST", '{S_AJAX_ACTION}', true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send(param);
//clear the message site
document.postform.message.value = '';
}
function handle_return()
{
if (xmlHttp.readyState == 4)
{
var load = document.getElementById('load');
load.parentNode.removeChild(load);
document.getElementById(fieldname).innerHTML += xmlHttp.responseText;
document.postform.reset();
}
}
function http_object()
{
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
</script>