4 Replies - 1449 Views - Last Post: 12 March 2013 - 09:32 AM

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Unrecognized expression: [native code]

Posted 12 March 2013 - 08:51 AM

Hi all,

I haven't used Javascript in a while, and I'm just starting to get into JQuery. (I would have posted in the JQuery forum, but I'm not fully sure if the problem I'm experiencing has to do with JQuery.) Anyway, I'm writing a simple function that should be able to load the output of a Perl script into a div:

// Externals.js
function myFunc( var1, var2 ) {
	var url = "constant_url_piece.pl?" + var1 + var2;
	$( '#myDiv' ).load( url );
}



The HTML I use to call this function is (obviously there are a few dummy variables in here, don't mind those):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>test</title>
	</head>
	<body>
		<div id="content">
<script type="text/javascript" src="path/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="path/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="path/Externals.js"></script>
<div id="myDiv">
</div>
<script type="text/javascript">myFunc( myVar1, myVar2 );</script>
		</div>
	</body>
</html>



And just to be clear, all the Javascript files are in the same folder. In the browser, this HTML shows up as a blank page, and in the Firefox error console I get the following error:

Error: uncaught exception: Syntax error, unrecognized expression: [native code]
}



I've been Googling both Javascript and JQuery all day and found no answers -- I can't tell if it's a Javascript problem or a JQuery problem. I'm leaning toward JQuery, because it looks like it's this line that causes the problem:

$( '#myDiv' ).load( url );



But I'm not sure, because I've looked all over and this seems to be the right syntax.

If anyone could give me a nudge in the right direction on this, I'd really appreciate it.

Thanks,
Zel2008

This post has been edited by Zel2008: 12 March 2013 - 08:53 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Unrecognized expression: [native code]

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3822
  • View blog
  • Posts: 13,543
  • Joined: 12-December 12

Re: Unrecognized expression: [native code]

Posted 12 March 2013 - 09:03 AM

Your code calls the function myFunc() while the page is loading, at which point the variables myVar1 and myVar2 have no value - they are undefined.

var url = "constant_url_piece.pl?" + var1 + var2;

You will be just joining var1 directly to var2. Url-parameters follow a specific format, usually ?somevar=somevalue&othervar=othervalue - I don't know if Perl uses different formatting, I assume it follows this same pattern.

This post has been edited by andrewsw: 12 March 2013 - 09:04 AM

Was This Post Helpful? 1
  • +
  • -

#3 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Unrecognized expression: [native code]

Posted 12 March 2013 - 09:20 AM

Thanks andrewsw,

I fixed up the function to be:
function myFunc( var1, var2 ) {
    var url = "constant_url_piece.pl?" + "var1=" + var1 + "&var2=" + var2;
    $( '#myDiv' ).load( url );
}



And it almost seems to work (thank you for the info so far!) -- var1 is passed correctly as a number. var2, however, is a string, and for some reason it's showing up in the URL as:

function var2() { [native code] } 



Is this because it's a string? I don't remember there ever being anything with Javascript that made string parameters turn into functions. Do I need to do an escape or something?

Thanks,
Zel2008

This post has been edited by Zel2008: 12 March 2013 - 09:24 AM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3822
  • View blog
  • Posts: 13,543
  • Joined: 12-December 12

Re: Unrecognized expression: [native code]

Posted 12 March 2013 - 09:26 AM

What value is assigned to myVar2, and does this happen before you call your function? That is, before you call your function with this line:

myFunc( myVar1, myVar2 );

myVar1 and 2 must be assigned values.
Was This Post Helpful? 0
  • +
  • -

#5 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 790
  • Joined: 06-January 09

Re: Unrecognized expression: [native code]

Posted 12 March 2013 - 09:32 AM

myVar1 is 1000, and myVar2 is "home" (without the quotation marks). Both of these values are set before the Javascript function is called. If I place a document.write() in the Javascript function, myVar1 is printed out as 1000, and myVar2 is printed out as function home() { [native code] }

Does that help?

EDIT: Never mind, I forgot the quotes around the string. *facepalm*

Thanks again for your help, I really appreciate it.

This post has been edited by Zel2008: 12 March 2013 - 09:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1