Hi all,
I've got a question about an AJAX issue that has me stumped. Hopefully someone else knows what the issue is. Below is a very simple AJAX request that works just fine until I put a simple statement inside of it. For the sake of simplicity, I've modified this AJAX request instead of posting the more complicated one I'm using - but essentially this example and the real code I'm using are failing for the same reason, because of line #4,
(var wlen = str.value.length). I had this working on my Mac, uploaded it to a Ubuntu server and it failed (no errors, just didn't work). Then for whatever reason, it stopped working on my Mac too.
<script type="text/javascript">
function name_search(str)
{
var wlen = str.value.length;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("name_div").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/it/device/action/name_search_new.php?q="+str,true);
xmlhttp.send();
}
</script>
- <script type="text/javascript">
- function name_search(str)
- {
- var wlen = str.value.length;
- var xmlhttp;
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("name_div").innerHTML=xmlhttp.responseText;
- }
- }
- xmlhttp.open("GET","/it/device/action/name_search_new.php?q="+str,true);
- xmlhttp.send();
- }
- </script>
-
The
name_search_new.php page grabs similar values to what is typed in the text box and returns those values. This page is irrelevant to this issue though because any php script will always fail with the line 4 new variable/assignment and it will always work with the variable/assignment gone.
If it helps, the request for this function is listed below... It also fails within a 'textarea' box too.
<input type="text" name="name" id="name" value="" style="color:red" placeholder="Device/Item (Required)" onkeyup="name_search(this.value)" />
- <input type="text" name="name" id="name" value="" style="color:red" placeholder="Device/Item (Required)" onkeyup="name_search(this.value)" />
-
Thanks in advance for your help!
Jay