This project is archived and is in readonly mode.

#868 ✓invalid
AHHP

Request and usage of evalScripts with DOM related scripts

Reported by AHHP | March 15th, 2010 @ 02:35 PM

Hi,

While using Request Class and set evalScripts to true, script tags will be executed and removed before sending response to OnSuccess event when response is string.
Please review sample below:

HTML Response:

<div id="myDiv">Some data</div>
<script type="text/javascript">
   document.id('myDiv').setStyle('color', 'red');
</script>
The codes won't work because there is no "myDiv" when script is run.
I solved it for my probem as below but i'm looking for a official and better solution:
Request.implement({
 success: function(text, xml){
  //this.onSuccess(this.processScripts(text), xml);
  this.onSuccess(text, xml);
 }
}); 
Element.implement({
 processScripts: function() {
  var scripts = this.getElements('script');
  scripts.each(function(script) {
   $exec( script.get('html') );
  });
  scripts.destroy();
  return this;
 }
}); 
new Request({
 ...
 onSuccess: function(response) {
  document.id('someWhere').set('html', response).processScripts();
 }
});

Regards,
AHHP

Comments and changes to this ticket

  • fakedarren

    fakedarren March 17th, 2010 @ 01:37 PM

    • State changed from “new” to “invalid”

    Hi AHHP,

    http://mootools.net/shell/ba7HK/

    If you use the Request.HTML class, once the scripts have been stripped, they are stored in the response property, and you can $exec them. Or, you get passed the javascript as the fourth argument of the onSuccess method and again you can $exec them.

    Check the docs for Request.HTML as the onSuccess arguments are different from regular Request.

    Also, it's best to ask these kinds of questions in our Google Group or IRC channel as you'll get a much quicker response.

    Cheers
    Darren

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages