PDA

View Full Version : Ajax browser problems


Jiberish
09-07-2008, 04:51 AM
I have the following script in a .js-file:



var xmlHttp

function showProducts(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}


var strs = str.split('_');

var str1=strs[0];

var str2=strs[1];

var str3=strs[2];


var url="list.php?"
url=url+"&subcat="+str1
url=url+"&cat="+str2
url=url+"&bra="+str3
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("ajaxy").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}


I call the script using the following HTML:


<a href="#" value="category_subcategory_brand_.html" onclick="showProducts(this.value)" >link</a>


It's working in IE, but no other browsers, any ideas? In FF and other browsers except IE the variable "str" comes up as undefined.

Thanks on beforehand.

Horus_Kol
09-07-2008, 07:21 PM
value is not a HTML4 attribute for an anchor element...

you could use the name or id attribute instead, or just pass the string itself:

<a href="#" onclick="showProducts('category_subcategory_brand_.html')" >link</a>

Jiberish
09-08-2008, 08:39 AM
Ahh..great! Thank you!