Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax Browser Compatibility

Status
Not open for further replies.

snowboardr

Programmer
Joined
Feb 22, 2002
Messages
1,401
Location
PH

I am somewhat new to Ajax, so bare with.. I need to modify the code below to work with opera 8 etc.. and it doesnt seem to be working in IE... I get the error "Error. Scripting for ActiveX might be disabled" but IE isnt disabled. The ajax works fine as far as saving, in Firefox.. etc


Code:
var xmlHttp

function SaveCollapse(intCall,SaveThis)
{ 
<!--
var url="ajax_save.asp?call=" + intCall + "&save=" + SaveThis
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
} 
//-->



function GetXmlHttpObject(handler)
{ 
<!--
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera") 
return; 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 
//-->
 
Maybe that's something really dumb! Why <!-- ... //--> kind of html comment within the script sector? That is unusal and errorneous! jscript engine is in no way recognizing them.
 
Not within a function! I don't think. Maybe I'm wrong?
 
I think so, because i have seen it done a million times enough to influence me to do it... :) do you know anything about the browser compatability js? I want to make sure the javascript checks to make sure its one of these browsers:

* Microsoft Internet Explorer version 5.0 and above, and browsers based on it (Mac OS versions not supported)
* Gecko-based browsers like Mozilla, Mozilla Firefox, SeaMonkey, Epiphany, Galeon and Netscape version 7.1 and above
* Browsers implementing the KHTML API version 3.2 and above, including Konqueror version 3.2 and above, and Apple Safari version 1.2 and above
* Opera browsers version 8.0 and above, including Opera Mobile Browser version 8.0 and above
* iCab version 3.0b352 and above
 
But a construction like this...
[tt]
function xyz(abc) {
<!-- [blue]//this line will be erroneous[/blue]
//etc etc
try {
//some lines
} catch(e) {
// some other lines [blue]//execution will be here?[/blue]
}
}
//-->
[/tt]
javascript engine reading the function will recognize only // or /* */ as comments, won't it not, but not <!--. It wouldn't know what it is?!
 
i havnt had any problems with it, but like i said i use it with ajax and have seen it thousands of times when looking at js on the web. It doesn't make sense to me either... ill be hoenst ;)
 
I have tested several config. To set the record straight, I think what you say is correct. <!-- within function brace won't cause a problem. Actually, I have never used that kind of construction and do not feel comfortable with it in principle. So I won't further divert member's attention to help on the core matter.
[tt]
function xyz(abc) {
<!--
//it seems no problem
//etc...
}
//-->
[/tt][tt]
function xyz(abc)
<!--
{
//will error out
}
//-->
[/tt][tt]
function xyz(abc) {
//etc...
<!--
//other things, no problem
//-->
}
[/tt][tt]
function xyz(abc) {
//etc...
<!--
//other things, sure problem not surprisingly
-->
}[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top