Demon
10-22-2008, 12:19 AM
I'm most certain that this has been mentioned before, however as it's most likely such a simple fix, I couldn't seem to find what I needed anywhere.
The problem I am experiencing is when I try to parse a value through javascript to PHP via AJAX. I have posted an example of what I mean below.
If in the name I type something like: A name with + and & and some other symbols, it does not get parsed through correctly, and the output from request.php is wrong. I hope somebody understands what I mean.
By the way, I have only posted parts of the script that I thought would be necessary to be seen in order to help.
Many thanks.
index.php:
echo '
<form name="makeRequestForm">
<table width="380" cellpadding="0" cellspacing="0" border="0" style="background-color: #cccccc;border: 1px #000 dotted; padding: 5px">
<tr>
<td>
<strong>Request Form</strong><br /><br />
What is your name?<br />
<input type="text" name="request_name" value="Test Value" /><br /><br /></td>
</tr>
<tr>
<td>
<input type="submit" value="Request" onclick="makeRequest(document.forms[\'makeRequestForm\'].request_name.value);return false;" />
<input type="submit" value="Cancel" onclick="requestBoxClose();return false;">
</td>
</tr>
</table>
</form>';
AJAX script:
function makeRequest(name) {
//Returns the correct value
alert('Sending with name: '+name);
ajaxHttp2=GetXmlHttpObject()
if (ajaxHttp2==null) {
alert ("Browser does not support HTTP Request")
return
}
var url="request.php"
url=url+"&songspy_name="+name
ajaxHttp2.onreadystatechange=completeRequest
ajaxHttp2.open("GET",url,true)
ajaxHttp2.send(null)
}
request.php:
echo '
<table width="380" cellpadding="0" cellspacing="0" border="0" style="background-color: #cccccc;border: 1px #000 dotted; padding: 5px">
<tr>
<td>
<strong>GWRadio Song Request</strong><br /><br />
Thank you, <strong>'.stripslashes($songspy_name).'</strong>.<br /><br /></td>
<tr>
</table>';
The problem I am experiencing is when I try to parse a value through javascript to PHP via AJAX. I have posted an example of what I mean below.
If in the name I type something like: A name with + and & and some other symbols, it does not get parsed through correctly, and the output from request.php is wrong. I hope somebody understands what I mean.
By the way, I have only posted parts of the script that I thought would be necessary to be seen in order to help.
Many thanks.
index.php:
echo '
<form name="makeRequestForm">
<table width="380" cellpadding="0" cellspacing="0" border="0" style="background-color: #cccccc;border: 1px #000 dotted; padding: 5px">
<tr>
<td>
<strong>Request Form</strong><br /><br />
What is your name?<br />
<input type="text" name="request_name" value="Test Value" /><br /><br /></td>
</tr>
<tr>
<td>
<input type="submit" value="Request" onclick="makeRequest(document.forms[\'makeRequestForm\'].request_name.value);return false;" />
<input type="submit" value="Cancel" onclick="requestBoxClose();return false;">
</td>
</tr>
</table>
</form>';
AJAX script:
function makeRequest(name) {
//Returns the correct value
alert('Sending with name: '+name);
ajaxHttp2=GetXmlHttpObject()
if (ajaxHttp2==null) {
alert ("Browser does not support HTTP Request")
return
}
var url="request.php"
url=url+"&songspy_name="+name
ajaxHttp2.onreadystatechange=completeRequest
ajaxHttp2.open("GET",url,true)
ajaxHttp2.send(null)
}
request.php:
echo '
<table width="380" cellpadding="0" cellspacing="0" border="0" style="background-color: #cccccc;border: 1px #000 dotted; padding: 5px">
<tr>
<td>
<strong>GWRadio Song Request</strong><br /><br />
Thank you, <strong>'.stripslashes($songspy_name).'</strong>.<br /><br /></td>
<tr>
</table>';