hlp w/ ajax javascript error (I posted the code this time)

S

SeanInSeattle

So, I'm getting an error on line 27, where I close the first catch
with a curly brace. Here's the code:

Code:
function ShowBlog(page){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience . . .</i></p>";
var xmlHttp;

//  Creating the xmlHttp var depending on the browser
try{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
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;
}
}
}
var url = "../php/blog-ReturnStr.php";
var params = "page=" + page + "accesslvl=" + <?php if
(isset($_SESSION['_ACCESSLVL'])){ echo $_SESSION['_ACCESSLVL']; } else
echo "1"; ?>;

xmlHttp.open("GET", url+"?"+params, true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('blog').innerHTML = xmlHttp.responseText;
}
else if (xmlHttp.readyState == 2 | 3){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience  . . .</i></p>";
}
}
xmlHttp.send(null);
}

Can anyone tell me why it would be giving me the error msg there? I'm
not getting the same error in Mozilla, and I've searched around and
haven't been able to find any info on issues with cross browser
support for try & catch.
 
S

SeanInSeattle

So, I'm getting an error on line 27, where I close the first catch
with a curly brace. Here's the code:

Code:
function ShowBlog(page){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience . . .</i></p>";
var xmlHttp;

//  Creating the xmlHttp var depending on the browser
try{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
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;
}
}
}
var url = "../php/blog-ReturnStr.php";
var params = "page=" + page + "accesslvl=" + <?php if
(isset($_SESSION['_ACCESSLVL'])){ echo $_SESSION['_ACCESSLVL']; } else
echo "1"; ?>;

xmlHttp.open("GET", url+"?"+params, true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('blog').innerHTML = xmlHttp.responseText;
}
else if (xmlHttp.readyState == 2 | 3){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience  . . .</i></p>";
}
}
xmlHttp.send(null);}

Can anyone tell me why it would be giving me the error msg there? I'm
not getting the same error in Mozilla, and I've searched around and
haven't been able to find any info on issues with cross browser
support for try & catch.

Weirder still, I'm getting a syntax error on the blank line right
after the if / else when trying to use something different than the
try / catch:

Code:
function ShowBlog(page){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience . . .</i></p>";
var xmlHttp;

//  Creating the xmlHttp var depending on the browser
var browser = navigator.appName; //find the browser name
if(browser == "Microsoft Internet Explorer"){
// Create the object using MSIE's method
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
// Create the object using other browser's method
xmlHttp = new XMLHttpRequest();
};

var url = "../php/blog-ReturnStr.php";
var params = "page=" + page + "accesslvl=" + <?php if
(isset($_SESSION['_ACCESSLVL'])){ echo $_SESSION['_ACCESSLVL']; } else
echo "1"; ?>;

xmlHttp.open("GET", url+"?"+params, true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('blog').innerHTML = xmlHttp.responseText;
}
else if (xmlHttp.readyState == 2 | 3){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience  . . .</i></p>";
}
}
xmlHttp.send(null);
}
 
P

Peter Michaux

So, I'm getting an error on line 27, where I close the first catch
with a curly brace.

What is the error message?

Line numbers won't mean much if code lines are long as the code is
wrapped at about 72 character width.

[snip code]

Peter
 
S

SeanInSeattle

So, I'm getting an error on line 27, where I close the first catch
with a curly brace.

What is the error message?

Line numbers won't mean much if code lines are long as the code is
wrapped at about 72 character width.

[snip code]

Peter

The error is showing up right after the "if(browser == "Microsoft
Internet Explorer"){ [create xmlhttp request object in MSIE] }
else{ [create xmlhttp request object for all other browsers] }" lines,
using either method for decision statements.

Thanks for your help!
 
T

Thomas 'PointedEars' Lahn

SeanInSeattle said:
So, I'm getting an error on line 27, where I close the first catch
with a curly brace.
What is the error message?

Line numbers won't mean much if code lines are long as the code is
wrapped at about 72 character width.
[...]

The error

.... that you still do not describe ...

http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork
is showing up right after the "if(browser == "Microsoft
Internet Explorer"){ [create xmlhttp request object in MSIE] }
else{ [create xmlhttp request object for all other browsers] }" lines,
using either method for decision statements.

Probably you have found out here that browser sniffing does not work.

http://PointedEars.de/scripts/test/whatami


PointedEars
 
L

Lee

SeanInSeattle said:
So, I'm getting an error on line 27, where I close the first catch
with a curly brace.

What is the error message?

Line numbers won't mean much if code lines are long as the code is
wrapped at about 72 character width.

[snip code]

Peter

The error is showing up right after the "if(browser == "Microsoft
Internet Explorer"){ [create xmlhttp request object in MSIE] }
else{ [create xmlhttp request object for all other browsers] }" lines,
using either method for decision statements.

Thanks for your help!

You might not realize it if you work with Internet
Explorer exclusively, but the words in error messages
are actually supposed to be useful information. Even
in Internet Explorer, they often contain useful hints.


--
 
R

Richard Cornford

Lee said:
SeanInSeattle said:
You might not realize it if you work with Internet
Explorer exclusively, but the words in error messages
are actually supposed to be useful information. Even
in Internet Explorer, they often contain useful hints.

Which is to say that there is a precise relationship between the cause
of an error and the message generated and that relationship can be
learnt. So, given the exact error text it is usually possible to know
what types of mistakes cause the error in question and so then to know
what to look for in the code. With the line/character numbers giving
some indication of where to look for that error (even if the location
they state is rarely the actual location of the error).

Richard.
 
V

VK

So, I'm getting an error on line 27, where I close the first catch
with a curly brace. Here's the code:
Code:
function ShowBlog(page){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience . . .</i></p>";
var xmlHttp;[/QUOTE]
[QUOTE]
//  Creating the xmlHttp var depending on the browser
try{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
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;
}
}
}
var url = "../php/blog-ReturnStr.php";
var params = "page=" + page + "accesslvl=" + <?php if
(isset($_SESSION['_ACCESSLVL'])){ echo $_SESSION['_ACCESSLVL']; } else
echo "1"; ?>;[/QUOTE]
[QUOTE]
xmlHttp.open("GET", url+"?"+params, true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('blog').innerHTML = xmlHttp.responseText;
}
else if (xmlHttp.readyState == 2 | 3){
document.getElementById('blog').innerHTML = "<p style=\"color:
orange; font-weight: bold;\"><i>Loading, I appreciate your
patience  . . .</i></p>";
}
}
xmlHttp.send(null);} [QUOTE]

Can anyone tell me why it would be giving me the error msg there? I'm
not getting the same error in Mozilla, and I've searched around and
haven't been able to find any info on issues with cross browser
support for try & catch.

Weirder still, I'm getting a syntax error on the blank line right
after the if / else when trying to use something different than the
try / catch: ....
var params = "page=" + page + "accesslvl=" + <?php if
(isset($_SESSION['_ACCESSLVL'])){ echo $_SESSION['_ACCESSLVL']; } else
echo "1"; ?>;[/QUOTE]
....
What is that? If you think that it has any relation to Javascript
syntax then you are sorrily mistaken and IE tells you about that ;-)

And now I am _really_ feel like go to Gecko, find the guy who did it
and sentence him for a life long exclusive VBA programming :-\ :-/

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script>
var params = "foobar" +
<?php if (isset($_SESSION['_ACCESSLVL'])){ echo
$_SESSION['_ACCESSLVL']; } ?>;
alert(params);
</script>
</head>
<body>
</body>
</html>

Alerts "foobar" I be damned, syntax is just fine from the point of
view Firefox 2.0.11
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top