HighDots Forums  

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

Javascript JavaScript language (comp.lang.javascript)


Discuss hlp w/ ajax javascript error (I posted the code this time) in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SeanInSeattle
 
Posts: n/a

Default hlp w/ ajax javascript error (I posted the code this time) - 12-15-2007 , 10:57 PM






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.

Reply With Quote
  #2  
Old   
SeanInSeattle
 
Posts: n/a

Default Re: hlp w/ ajax javascript error (I posted the code this time) - 12-15-2007 , 11:19 PM






On Dec 15, 8:57 pm, SeanInSeattle <WakieWa... (AT) gmail (DOT) com> wrote:
Quote:
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); }


Reply With Quote
  #3  
Old   
Peter Michaux
 
Posts: n/a

Default Re: hlp w/ ajax javascript error (I posted the code this time) - 12-15-2007 , 11:55 PM



On Dec 15, 8:57 pm, SeanInSeattle <WakieWa... (AT) gmail (DOT) com> wrote:
Quote:
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


Reply With Quote
  #4  
Old   
SeanInSeattle
 
Posts: n/a

Default Re: hlp w/ ajax javascript error (I posted the code this time) - 12-16-2007 , 12:28 AM



On Dec 15, 9:55 pm, Peter Michaux <petermich... (AT) gmail (DOT) com> wrote:
Quote:
On Dec 15, 8:57 pm, SeanInSeattle <WakieWa... (AT) gmail (DOT) com> wrote:

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!


Reply With Quote
  #5  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: hlp w/ ajax javascript error (I posted the code this time) - 12-16-2007 , 12:05 PM



SeanInSeattle wrote:
Quote:
On Dec 15, 9:55 pm, Peter Michaux <petermich... (AT) gmail (DOT) com> wrote:
On Dec 15, 8:57 pm, SeanInSeattle <WakieWa... (AT) gmail (DOT) com> wrote:
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_not...ml#ps1DontWork

Quote:
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
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
  #6  
Old   
Lee
 
Posts: n/a

Default Re: hlp w/ ajax javascript error (I posted the code this time) - 12-16-2007 , 12:28 PM



SeanInSeattle said:
Quote:
On Dec 15, 9:55 pm, Peter Michaux <petermich... (AT) gmail (DOT) com> wrote:
On Dec 15, 8:57 pm, SeanInSeattle <WakieWa... (AT) gmail (DOT) com> wrote:

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.


--



Reply With Quote
  #7  
Old   
Richard Cornford
 
Posts: n/a

Default Re: hlp w/ ajax javascript error (I posted the code this time) - 12-16-2007 , 01:59 PM



Lee wrote:
Quote:
SeanInSeattle said:
snip
The error is showing up right after the "...
snip
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.



Reply With Quote
  #8  
Old   
Randy Webb
 
Posts: n/a

Default Re: hlp w/ ajax javascript error (I posted the code this time) - 12-16-2007 , 02:41 PM



Richard Cornford said the following on 12/16/2007 2:59 PM:
Quote:
Lee wrote:
SeanInSeattle said:
snip
The error is showing up right after the "...
snip
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).
There is more to decrypting IE error messages than simply learning what
the message means.

Line 2
Character 1
Invalid Character

You can pull your hair out trying to figure that one out before you
either figure it out by trial and error or find someone to tell you what
it usually means.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.