evalscripts, y u no worky?

30 views
Skip to first unread message

aowie

unread,
Nov 16, 2008, 11:31:56 PM11/16/08
to MooTools Users
So ive noticed that I am not the only one around here that cant get a
correct eval response from externally loading other js scripts through
Request or Request.HTML

Ive stripped out only what is necessary for debugging purposes here:
http://istoleyourbaby.com/test.html

the HTML loads perfectly but the js in the same page is stripped and
disappears. Tis a very strange thing, and I need some fresh eyes on
this one... mine are getting weary.

The js that needs to be loaded is a simple default value filler and
style adjuster. The js works fine elsewhere it just is getting
stripped. So can anyone tell me if my syntax is wrong somewhere
maybe.. or am i just missing something obvious?

Any help is appreciated, thanks!

Oskar Krawczyk

unread,
Nov 17, 2008, 6:59:57 AM11/17/08
to MooTools Users
Hi, you're saying the JS is "in the same page" but when I look into
login.php source there is no JS there. So what I assume you mean is
that the SECOND file you load is being stripped.

Well it's not – the JS file simply doesn't even load in the request –
at least that's what Firebug shows.

Best,
Oskar

Steve Onnis

unread,
Nov 17, 2008, 8:04:55 AM11/17/08
to mootool...@googlegroups.com
Are you saying there is means to be js code in
http://istoleyourbaby.com/login.php ? Because there isnt.....

aowie

unread,
Nov 17, 2008, 11:39:24 AM11/17/08
to MooTools Users
OK update on this post:

Sorry guys i was using login.php as a module on other pages too, so i
mustve taken out the js due to it not working.

Anyways, I have made a dupe of that page with the js put back in, and
it still produces the same result.
I have also added both types of requests to help debug this situation.
Request and Request.HTML
You'll notice that if you click Request, only one instance loads in
the appropriate div. But if you use the Request.HTML multiple
instances load and the javascript will load on the first response
after the second click, but only the first response???

i had evalscripts set to true on the first request, but it broke it...
and Request.HTML has it set to true, but no evaluation until the 2nd
click.
not to mention the error it returns "ob.toString is not a function".

Let me know if you want me to add in anything else to help debug this.
Thanks!

On Nov 17, 6:04 am, "Steve Onnis" <st...@cfcentral.com.au> wrote:
> Are you saying there is means to be js code inhttp://istoleyourbaby.com/login.php?  Because there isnt.....

aowie

unread,
Nov 17, 2008, 6:59:29 PM11/17/08
to MooTools Users
SOLUTION!
Apparently there are some known bugs with Request.HTML...

responseJavascript is to be used somehow within the onSuccess, but im
not quite sure how...

anyways the thanks to shanebo, i was able to produce a working
solution

example:
var myScript = new Asset.javascript('/scripts/testScript.js', {id:
'testScript'});

you'll need to load the Assets library in order for it to understand
Asset though.
but make sure you define your js as an asset AFTER you load your HTML
elements.

marlus

unread,
Nov 17, 2008, 9:03:58 PM11/17/08
to MooTools Users
Hello aowie,
im happy that you have it done!
Can you post all your solution here?

you are declaring that var myscript inside the onSuccess function?
what i understood is that we load an js file and can call its
functions by the id, is that correct?

aowie

unread,
Nov 18, 2008, 11:43:14 AM11/18/08
to MooTools Users
<html>
<head>
<script type="text/javascript" src="scripts/mootools.js"></
script>
<script type="text/javascript" src="scripts/mootools-1.2-
more.js"></script>

<script language="javascript">
window.addEvent('domready', function() {

var showLogin2 = new Request.HTML({ //loads sign in form
url: 'logintest.php',
evalScripts: true,
onSuccess: function(responseTree, responseElements, responseHTML,
responseJavaScript) {
$('formContainer').set('html', responseHTML);
var myScript = new Asset.javascript('/scripts/testScript.js',
{id: 'testScript'});
},
onFailure: function() {
$('formContainer').set('text', 'The request failed.');
}
});

$('loginLink2').addEvent('click', function(e){
e.stop();
showLogin2.send();
});
});
</script>

</head>
<body>
<a id="loginLink2" href="#">Request.HTML</a>
<div id="formContainer"></div>
</body>
</html>

the example in my last post came straight out of the mootools docs
found here:
http://mootools.net/docs/Plugins/Assets

although the properties, such as id, arent necessary for making it
work.

I took the liberty of doing a test with a function i've created in the
externally loaded js. So far I have not found how to reference
functions within the new Asset. I've tried the following with no
success:

function written to the Asset file:
function tester(){
alert('blah');
}

tested (but failed):
myScript.tester(); <---the var associated to the js file
testScript.tester(); <-- the id set in the properties of the js file
tester(); <-- plain function call

i have also tried referencing a simple var that was defined in the
external js with the same methods as above.. the var is recognized..
but the output is undefined.

FYI all of these methods were tested directly AFTER the js was loaded
(a.k.a the next line down)
So youd think it would work right? ...wrong. What good is having an
Asset you can't use??!?!?!
I think the docs for mootools needs to get a serious revamping, most
everything in there is so generic and less in depth than Carrot Top's
jokes

Anyways, let me know if anyone figures out how to call to functions
within a defined Asset.

marlus

unread,
Nov 18, 2008, 3:01:18 PM11/18/08
to MooTools Users
There is no options like the onload/onerror/onabout events like image
asset?
How we know the js file was loaded?

marlus

unread,
Nov 18, 2008, 3:07:23 PM11/18/08
to MooTools Users
I've found this link in the old forum:
http://forum.mootools.net/topic.php?id=3128

The bad notice is some incompatibilities in assets onload methods, but
here is the code with onload:

var js = new Asset.javascript('firebug.js', {
onload: initTiny
});
function initTiny() {
alert('I\'m working on both IE6 and IE7');
}

On 18 nov, 14:43, aowie <aow...@gmail.com> wrote:

marlus

unread,
Nov 18, 2008, 3:41:12 PM11/18/08
to MooTools Users
I've made a test that worked in all browsers:

test.html code:

window.addEvent('domready', function() {
var myScript = new Asset.javascript('test.js',{id: 'test',
onload:afterLoad});
function afterLoad(){
testing();
$("button").addEvent('click',testing);
}
});

- - - - -

test.js code:

function testing(){
alert("its working");
Reply all
Reply to author
Forward
0 new messages