XMLHttpRequest - unterminated string constant javascript error

W

William

I have the following javascript function that updates a scroll_list and
sends the updated entry (with its index) to a server script
( i.e. http://mkmxg00/cgi/confirmUpload.pl ) for further processing:

function saveText( scroll_list, t_area, listToBeUpdated ) {
scroll_list.options[scroll_list.selectedIndex].text = t_area.text;
scroll_list.options[scroll_list.selectedIndex].value= t_area.value;

var req;
var url = "http://mkmxg00/cgi/confirmUpload.pl";

if ( window.XMLHttpRequest ) {
try {
req = new XMLHttpRequest();
}
catch( e ) {
req = false;
}
}
else if ( window.ActiveXObject ) {
try {
req = new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch( e ) {
try {
req = new ActiveXObject( "Microsoft.XMLHTTP" );
}
catch( e ) {
req = false;
}
}
if ( req ) {
req.onreadystatechange = processReqChange;
req.open( "POST", url, true );

// req.send( null );

req.send( "client side" );
req.send( "2nd piece of data from client side: " + i + "\n" );
}
}
}

function processReqChange() {
alert( req.readyState );
if ( req.readyState == 4 ) {
if ( req.status == 200 ) {
// process the response if successful
alert( "passed!" );
}
}
else {
alert( req.readyState + ", " + req.status );
}
}


I tried the following reference:
http://www.xml.com/pub/a/2005/02/09/xml-http-request.html

My questions:
1) what caused the "unterminated string constant error"? I don't see any
', \r, etc in my javascript variables.

2) If I want to send() to the server the scroll_list option, and that
option's index to the server script http://mkmxg00/cgi/confirmUpload.pl
for further processing, am I using send() correctly? If not, please
correct by providing an example.
 
T

Thomas 'PointedEars' Lahn

William said:
[...]
if ( req ) {
req.onreadystatechange = processReqChange;
req.open( "POST", url, true );

XMLHttpRequest.prototype.open() is described to clear all event listeners,
so you should switch the order of the last two statements.

// req.send( null );

req.send( "client side" );
req.send( "2nd piece of data from client side: " + i + "\n"
);
}
[...]
I tried the following reference:
http://www.xml.com/pub/a/2005/02/09/xml-http-request.html

You better look at the source: see

<URL:http://msdn.microsoft.com/library/en-us/xmlsdk/html/7924f6be-c035-411f-acd2-79de7a711b38.asp>

and the URI above.
My questions:
1) what caused the "unterminated string constant error"? I don't see any
', \r, etc in my javascript variables.

The code you posted is syntactically correct. The error must be elsewhere.
Since you did not post how you call the saveText() method, it is possible
that the method call creates the problem.

2) If I want to send() to the server the scroll_list option, and that
option's index to the server script http://mkmxg00/cgi/confirmUpload.pl
for further processing, am I using send() correctly?

No. It does not make sense to make several independent asynchronous POST
requests to the same resource without changing the event listener. You
should get informed about HTTP; read RFC1945 and RFC2616.
If not, please correct by providing an example.

req.send(
"client side"
+ "2nd piece of data from client side: " + i + "\n");

BTW: This is the fourth thread started by you dealing with the same main
problem. I would appreciate it -- and I am sure I am not the only one here
-- if you would not start a new thread unless the main problem to be solved
changes significantly; instead please continue the existing thread (post a
followup). RT[fp]ineM or use a newsreader application that you can handle
instead.


PointedEars
 
W

William

William said:
[...]
if ( req ) {
req.onreadystatechange = processReqChange;
req.open( "POST", url, true );

XMLHttpRequest.prototype.open() is described to clear all event listeners,
so you should switch the order of the last two statements.

I switched the order of the last 2 statements. Unfortunately I got the
same error.
// req.send( null );

req.send( "client side" );
req.send( "2nd piece of data from client side: " + i + "\n"
);
}
[...]
I tried the following reference:
http://www.xml.com/pub/a/2005/02/09/xml-http-request.html

You better look at the source: see

<URL:http://msdn.microsoft.com/library/en-us/xmlsdk/html/7924f6be-c035-411f-acd2-79de7a711b38.asp>

and the URI above.

i have already read this MSDN reference before posting.
The code you posted is syntactically correct. The error must be elsewhere.
Since you did not post how you call the saveText() method, it is possible
that the method call creates the problem.

saveText() was called in the following 2 places:

print $query->td(
$query->textarea(-name=>'BOFOTickers'),
$query->p,
$query->button(-name=>'ADD',
-value=>'Confirm Modifications',
-onClick=>"saveText( this.form.bo_fo_tickers,
this.form.BOFOTickers, this.form.bo_fo_tickers )"),
$query->button(-name=>'REMOVE',
-value=>'Edit Selected Entry',
-onClick=>"edit(this.form.bo_fo_tickers,
this.form.BOFOTickers)"));

print $query->td(
$query->textarea(-name=>'BOFOEmails'),
$query->p,
$query->button(-name=>'ADD',
-value=>'Confirm Modifications',
-onClick=>"saveText( this.form.bo_fo_emails,
this.form.BOFOEmails, this.form.bo_fo_emails )"),
$query->button(-name=>'REMOVE',
-value=>'Edit Selected Entry',
-onClick=>"edit( this.form.bo_fo_emails,
this.form.BOFOEmails)"));
also read this URL before posting; but the line number and character given
in the javascript error message is wrong - it refers to an unrelated place
in my source code file.

The error is intermittent - sometimes even when the page loads up, I got
the same javascript unterminated string constant error.
 
T

Thomas 'PointedEars' Lahn

William said:
William said:
[...]
if ( req ) {
req.onreadystatechange = processReqChange;
req.open( "POST", url, true );

XMLHttpRequest.prototype.open() is described to clear all event
listeners, so you should switch the order of the last two statements.

I switched the order of the last 2 statements. Unfortunately I got the
same error.

It was a Good Thing anyway.
[...]
My questions:
1) what caused the "unterminated string constant error"? I don't see
any ', \r, etc in my javascript variables.

The code you posted is syntactically correct. The error must be
elsewhere. Since you did not post how you call the saveText() method, it
is possible that the method call creates the problem.

saveText() was called in the following 2 places:

[probably server-side code]

Whatever this is, it is not JS/ECMAScript. Post client-side code if you
have a problem with client-side scripting, and post only JS/ECMAScript code
here.
also read this URL before posting; but the line number and character given
in the javascript error message is wrong - it refers to an unrelated place
in my source code file.

Of course it is wrong. It is referring to the generated (client-side) code,
not the generating (server-side) one.


PointedEars
 
W

William

On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]
Of course it is wrong. It is referring to the generated (client-side) code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line 99,
character 5.

The client-side code would be the HTML page. But I tried view->source
from my brower, and my HTML code has only 48 lines. So where is this
"line 99, character 5" come from?
 
R

Randy Webb

William said the following on 1/25/2006 10:36 AM:
On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]
Of course it is wrong. It is referring to the generated (client-side)
code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line 99,
character 5.

The client-side code would be the HTML page. But I tried view->source
from my brower, and my HTML code has only 48 lines. So where is this
"line 99, character 5" come from?

Do you have any external .css files or .js files referenced? Those lines
of code will be included when counting line numbers. The same as if you
had not used external files but pasted the contents into the HTML file.

If not, then post a URL to a sample page that shows the error.
 
W

William

William said the following on 1/25/2006 10:36 AM:
On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]
<URL:http://jibbering.com/faq/#FAQ4_43>
also read this URL before posting; but the line number and character
given
in the javascript error message is wrong - it refers to an unrelated
place
in my source code file.

Of course it is wrong. It is referring to the generated (client-side)
code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line 99,
character 5.

The client-side code would be the HTML page. But I tried view->source from
my brower, and my HTML code has only 48 lines. So where is this "line 99,
character 5" come from?

Do you have any external .css files or .js files referenced? Those lines of
code will be included when counting line numbers. The same as if you had not
used external files but pasted the contents into the HTML file.

No .css nor .js files referenced.
If not, then post a URL to a sample page that shows the error.
http://mkmxg00/cgi/extra_desks_upload_list.pl
 
R

Randy Webb

William said the following on 1/25/2006 11:00 AM:
William said the following on 1/25/2006 10:36 AM:
On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]

<URL:http://jibbering.com/faq/#FAQ4_43>
also read this URL before posting; but the line number and
character given
in the javascript error message is wrong - it refers to an
unrelated place
in my source code file.

Of course it is wrong. It is referring to the generated
(client-side) code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line 99,
character 5.

The client-side code would be the HTML page. But I tried
view->source from my brower, and my HTML code has only 48 lines. So
where is this "line 99, character 5" come from?

Do you have any external .css files or .js files referenced? Those
lines of code will be included when counting line numbers. The same as
if you had not used external files but pasted the contents into the
HTML file.

No .css nor .js files referenced.
If not, then post a URL to a sample page that shows the error.
http://mkmxg00/cgi/extra_desks_upload_list.pl

I get a Page Not Found for that URL.
 
T

Thomas 'PointedEars' Lahn

William said:
No .css nor .js files referenced.

Is the generated source code valid markup (<URL:http://validator.w3.org/>)
Are there any other `link' or `script' elements in your client-side source
code? If yes, which ones? Which user agent(s) are you testing with (post
the name and version along with the value of navigator.userAgent)?
^^^^^^^
A _fully qualified_ domain name would have been helpful.


PointedEars
 
W

William

William said the following on 1/25/2006 11:00 AM:
William said the following on 1/25/2006 10:36 AM:
On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]

<URL:http://jibbering.com/faq/#FAQ4_43>
also read this URL before posting; but the line number and character
given
in the javascript error message is wrong - it refers to an unrelated
place
in my source code file.

Of course it is wrong. It is referring to the generated (client-side)
code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line 99,
character 5.

The client-side code would be the HTML page. But I tried view->source
from my brower, and my HTML code has only 48 lines. So where is this
"line 99, character 5" come from?

Do you have any external .css files or .js files referenced? Those lines
of code will be included when counting line numbers. The same as if you
had not used external files but pasted the contents into the HTML file.

No .css nor .js files referenced.
If not, then post a URL to a sample page that shows the error.
http://mkmxg00/cgi/extra_desks_upload_list.pl

I get a Page Not Found for that URL.

my bad. please try:
http://mkmxg00.cibg.tdbank.ca/cgi/extra_desks_upload_list.pl
 
R

Randy Webb

William said the following on 1/25/2006 11:48 AM:
William said the following on 1/25/2006 11:00 AM:
On Wed, 25 Jan 2006, Randy Webb wrote:

William said the following on 1/25/2006 10:36 AM:
On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]

<URL:http://jibbering.com/faq/#FAQ4_43>
also read this URL before posting; but the line number and
character given
in the javascript error message is wrong - it refers to an
unrelated place
in my source code file.

Of course it is wrong. It is referring to the generated
(client-side) code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line 99,
character 5.

The client-side code would be the HTML page. But I tried
view->source from my brower, and my HTML code has only 48 lines.
So where is this "line 99, character 5" come from?

Do you have any external .css files or .js files referenced? Those
lines of code will be included when counting line numbers. The same
as if you had not used external files but pasted the contents into
the HTML file.

No .css nor .js files referenced.

If not, then post a URL to a sample page that shows the error.
http://mkmxg00/cgi/extra_desks_upload_list.pl

I get a Page Not Found for that URL.

my bad. please try:
http://mkmxg00.cibg.tdbank.ca/cgi/extra_desks_upload_list.pl

I still get a Page Not Found for that URL as well
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 1/25/2006 11:24 AM:
Which user agent(s) are you testing with (post the name and
version along with the value of navigator.userAgent)?


I don't see the wisdom in requesting the navigator.userAgent string when
it is widely known to be worthless for anything other than a place holder.

Browser name and version tells you more than the userAgent string could
ever be good for.
 
R

Randy Webb

Randy Webb said the following on 1/25/2006 12:00 PM:
William said the following on 1/25/2006 11:48 AM:
William said the following on 1/25/2006 11:00 AM:
On Wed, 25 Jan 2006, Randy Webb wrote:

William said the following on 1/25/2006 10:36 AM:
On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]

<URL:http://jibbering.com/faq/#FAQ4_43>
also read this URL before posting; but the line number and
character given
in the javascript error message is wrong - it refers to an
unrelated place
in my source code file.

Of course it is wrong. It is referring to the generated
(client-side) code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line
99, character 5.

The client-side code would be the HTML page. But I tried
view->source from my brower, and my HTML code has only 48 lines.
So where is this "line 99, character 5" come from?

Do you have any external .css files or .js files referenced? Those
lines of code will be included when counting line numbers. The same
as if you had not used external files but pasted the contents into
the HTML file.

No .css nor .js files referenced.

If not, then post a URL to a sample page that shows the error.
http://mkmxg00/cgi/extra_desks_upload_list.pl

I get a Page Not Found for that URL.

my bad. please try:
http://mkmxg00.cibg.tdbank.ca/cgi/extra_desks_upload_list.pl

I still get a Page Not Found for that URL as well

Have you tried testing the page in Mozilla? The error messages there
aren't as cryptic as IE Error Messages.
 
W

William

Randy Webb said the following on 1/25/2006 12:00 PM:
William said the following on 1/25/2006 11:48 AM:
On Wed, 25 Jan 2006, Randy Webb wrote:

William said the following on 1/25/2006 11:00 AM:
On Wed, 25 Jan 2006, Randy Webb wrote:

William said the following on 1/25/2006 10:36 AM:
On Wed, 25 Jan 2006, Thomas 'PointedEars' Lahn wrote:

[...]

<URL:http://jibbering.com/faq/#FAQ4_43>
also read this URL before posting; but the line number and character
given
in the javascript error message is wrong - it refers to an unrelated
place
in my source code file.

Of course it is wrong. It is referring to the generated
(client-side) code,
not the generating (server-side) one.

"unterminated string constant javascript error" occured on line 99,
character 5.

The client-side code would be the HTML page. But I tried view->source
from my brower, and my HTML code has only 48 lines. So where is this
"line 99, character 5" come from?

Do you have any external .css files or .js files referenced? Those
lines of code will be included when counting line numbers. The same as
if you had not used external files but pasted the contents into the
HTML file.

No .css nor .js files referenced.

If not, then post a URL to a sample page that shows the error.
http://mkmxg00/cgi/extra_desks_upload_list.pl

I get a Page Not Found for that URL.

my bad. please try:
http://mkmxg00.cibg.tdbank.ca/cgi/extra_desks_upload_list.pl

I still get a Page Not Found for that URL as well

Have you tried testing the page in Mozilla? The error messages there aren't
as cryptic as IE Error Messages.

I don't get this javascript error in Firefox 1.0.7.
 
W

William

Is the generated source code valid markup (<URL:http://validator.w3.org/>)
It did not. But I have trouble interpreting some of the error messages on
http://validator.w3.org/check

e.g.
# Error Line 27 column 14: there is no attribute "NAME".

<frame name="banner" scrolling="no" noresize target="main"
marginwidth="0" mar

There *is* an attribute called "name".


Also, is
Error Line 46 column 6: end tag for "HTML" which is not
finished.

</html>

Are there any other `link' or `script' elements in your client-side source
code? If yes, which ones? Which user agent(s) are you testing with (post
the name and version along with the value of navigator.userAgent)?
script elements:
<SCRIPT LANGUAGE="JavaScript">
<!--
// Do this here to ensure that the last page to load is the secured.
// This will make sure that a login appears in case we need
authentication.
function refreshFrame() {
frames['main'].window.location.href = "/html/about.html";
}
-->

link elements:

if the user's brower does not support frames:
<p>This site uses frames, which, unfortunately are not supported by your
browser. For best results, please use:
<A HREF="http://www.microsoft.com/ie/">MS Internet Explorer</A>.


not really a link element, but a frame populated with another web page.

<frame name="navigation" target="main" marginwidth="0"
marginheight="0"
frameborder="no" src="/html/menus.html">

likewise:

<frame name="banner" scrolling="no" noresize target="main"
marginwidth="0" marginheight="0" frameborder="no" src="/jsp/banner.jsp">

and:
<frame name="main" frameborder="no" src="blank.html">
 
T

Thomas 'PointedEars' Lahn

William said:
William said:
36 AM:
"unterminated string constant javascript error" occured on line 99,
character 5.
The client-side code would be the HTML page. But I tried view->source
from my brower, and my HTML code has only 48 lines. So where is this
"line 99, character 5" come from?
[...]
Is the generated source code valid markup
(<URL:http://validator.w3.org/>)
It did not. But I have trouble interpreting some of the error messages on
http://validator.w3.org/check

e.g.
# Error Line 27 column 14: there is no attribute "NAME".

<frame name="banner" scrolling="no" noresize target="main"
marginwidth="0" mar

There *is* an attribute called "name".

There is one for this element, declared in HTML 4.01 _Frameset_. Probably
your document does not include a DOCTYPE declaration before the root `html'
element, and so the Validator assumes HTML 4.01 Transitional in order to
continue validation tentatively. There is no `frame' element in the latter
HTML 4 variant, so no `name' attribute for that element.

Include

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">

before

<html>

and Revalidate.
Also, is
Error Line 46 column 6: end tag for "HTML" which is not
finished.

</html>

This is simply not true. View->Source gives: </html>

The element is not considered finished because its content is not Valid.
Enable Verbose Output (check the checkbox and select Revalidate), read the
explanations and the FAQ they are pointing to.
script elements:

Please always delimit new text from quoted text with an empty line, thanks.
<SCRIPT LANGUAGE="JavaScript">

Should be

<script type="text/javascript">

as the Validator also tells you.

Omit that, it is deprecated because it is no longer necessary (pre-3.2 HTML
is obsolete) and is error-prone. The Validator does not recognize this as
an error because it is properly delimiting a "comment declaration" in SGML.
However, a (disregarded) comment is not what you wanted the content of the
`script' element to be :)
// Do this here to ensure that the last page to load is the secured.
// This will make sure that a login appears in case we need
authentication.
function refreshFrame() {
frames['main'].window.location.href = "/html/about.html";
}

A bit more feature testing here is certainly a Good Thing:

function refreshFrame()
{
var f;
if (typeof window != "undefined"
&& (f = window.frames)
&& (f = f['main'])
&& f.location)
{
f.location = "/html/about.html";
}
}
^
This is a syntax error. `--' is the decrement operator, a reference is
expected as its argument. Omit this line, see above.
link elements:

[...]
<A HREF="http://www.microsoft.com/ie/">MS Internet Explorer</A>.


not really a link element, but a frame populated with another web page.

It is not "a frame populated with another web page" either. FYI, a `link'
element looks like this:

<link ...>

Although I doubt they can create this particular problem: Are there any
`style' elements?
<frame name="navigation" target="main" marginwidth="0"
marginheight="0"
frameborder="no" src="/html/menus.html">

likewise:

<frame name="banner" scrolling="no" noresize target="main"
marginwidth="0" marginheight="0" frameborder="no" src="/jsp/banner.jsp">

and:
<frame name="main" frameborder="no" src="blank.html">

It could also be code in either frame that is causing the error.


HTH

PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Omit that, it is deprecated because it is no longer necessary (pre-3.2
HTML is obsolete) and is error-prone. The Validator does not recognize
this as an error because it is properly delimiting a "comment declaration"
in SGML.

While the latter is usually true, it does not apply here. In fact, the
content of the `script' element is CDATA, not PCDATA, in HTML. Which is
why the Validator's SGML parser is only looking for the End Tag Open
Delimiter </. It cannot recognize script syntax errors.
However, a (disregarded) comment is not what you wanted the content of the
`script' element to be :)

Any SGML parser that regards this as a comment is broken. However,
any XML parser that regards this as a comment is working as designed.

Sorry for causing confusion.


PointedEars
 
T

Thomas 'PointedEars' Lahn

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,930
Messages
2,570,072
Members
46,521
Latest member
JamieCooch

Latest Threads

Top