WebDialog JS reading beyond end of file - sending message to Ruby

webdialog
javascript

#1

I have a ‘working’ WebDialog, which does what I want it to do, and is passing messages between JS and Ruby.

But it is triggering an error when using Martin Rinehart’s code to send the message from JS to Ruby.

When I make the function do nothing by removing its contents, I don’t get the error. When I leave those lines in, the code ‘works’ to send message to Ruby, but gets the EOF error (actually pointing to the end of the first line of the HTML page, which is an HTML comment).

Here’s the line that calls it, and the function:

     ...
      sendToRuby( 'get_inputs', result );
    } // End if formValid
  } // End function button_clicked

// --------------------------------------------------------------------------------------
// The following three JS functions, and the Ruby callback functions get_inputs() and set_values()
//  work together to pass messages back and forth between this WebDialog page's input fields and Ruby
	function sendToRuby( cb_name, msg ) {
		fake_url = 'skp:' + cb_name + '@' + msg;
		window.location.href = fake_url;
	}// End function sendToRuby

...

And it produces this error message in the console when run.

[Error] SyntaxError: Unexpected EOF
	(anonymous function) (JWM_wd_InputBox.html:1)

Do I just ignore this? Or is there another way of getting JS to send to Ruby?

PS. When testing just the HTML page in Chrome, I don’t see this error. But on my iMac, the WebDialog is running the Safari WebKit, and the WebDialog is opened by Ruby.


#2

What about just:

window.location = fake_url;

What console ? Not the Ruby Console? (It does not look like a Ruby exception message.)


#3

I’ll try that, Dan.

And it’s in the Safari WebKit console - a JS error message.


#4

Doesn’t make any difference - same error about reading beyond EOF.

I remember in a post on this forum which commented about this way of communicating that it was ‘deprecated’, but gave no alternative. That suggests there may be some other way, but I don’t know what it might be.

I’m fairly sure there aren’t any JS syntax errors in the rest of the file after this function. There are other functions, and they all work, and I’ve checked visually for any missing end of line semicolons, or mismatched braces.

And as I said earlier, when I comment out the two lines IN the function, I don’t get the error (but of course, I also don’t get anything sent to Ruby).

Since it appears to work, and in use the console won’t be open, I can leave it as it is, but I’d like to know what might be causing it.


#5

make sure you are escaping the message - quotes in particular are problematic. A simple debug might be to alert(fake_url);


#6

@john_mcclenahan if you are testing this for passing lengths from javascript to ruby, @jim_foltz may have hit it on the head. For example, a string formatted in feet and inches has both a single quote character and a double quote character embedded!


#7

Another thing I have seen cause strange syntax errors, is file character encoding. Try to use UTF-8 as your HTML encoding.

And in the <head> element:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

See: W3CSchools: What is HTML Character Encoding?


#8

I’ve successfully escaped both single and double quotes in lengths - did that early on during development using the HTML &apos; and &quot; strings to replace the quote characters (and decode them at the other end). And in spite of this Unexpected EOF error, the correct string is passed (in both directions).

So this error should not be caused by quotes.

It may be that I need something in the <head>or even earlier, document type, specification to clarify that I (think) I am using UTF8 encoding. There’s a recent post (i think from Dan) about specifying which browser you are targeting, too, that I need to fix.

Will have to google for the details.


#9

Well, I’ve added these tags to the html page.

<!DOCTYPE html>
<meta charset="UTF-8">

I still get the Unexpected EOF error.

And the WebDialog is still working.

I think I’ll leave it that way for the moment.

I’ll start a different topic proposing where I’ve got to as a simple webInputBox replacement, that I’ve been working on for a couple of weeks, since asking for help on getting started. It’s got a long way since then.

That topic is here, with the full code as an installable RBZ file.


#10

it’s possibly the mix of tabs and spaces causing the ‘minor’ error…

I always ‘detab’ ruby html, css and js before running…

line endings can also cause issues…

john


#11

Thanks, I’ll try that and see if it helps. I’m using TextWrangler on Mac - not v familiar with it yet, but I expect it will do that, once I figure out how


#12

Text menu second from bottom…

john


#13

Just got it. Tried (detabbing, that is). Makes no difference to the error, unfortunately