Forum: Rails Spinoffs (closed, excessive spam) Evaluate form request

09b36db86f0d97d534b9f5a6fea7deb1?d=identicon&s=25 marius@thehendonmob.com (Guest)
on 2008-06-10 14:53
(Received via mailing list)
Hi,

I am having trouble with evaluation of submitted form. I do this:

<input type="button" value="click me" onclick="javascript:
  $('myform').request({
    method: 'post',
    onComplete: submit_update
  });">

The form is submitted properly and submit_update function is called
upon completion. The thing is that the returned html code contains
javascripts which should be evaluated and I simply can't force
prototype to do this. I tried evalScripts: true but it doesn't work.
Any ideas? Thanks.
F490e41cd5de1393a9f6958b70dae6ab?d=identicon&s=25 Frederick Polgardy (Guest)
on 2008-06-10 15:28
(Received via mailing list)
The evalScripts option is used by Ajax.Updater to evaluate the scripts
in an
Ajax request before updating an element.  Ajax.Request (which is what
form.request() boils down to) doesn't do any evaluation or updating for
you,
you have to do it yourself.  In the body of your handler, you will have
to
do something like the following:

function submit_update(response) {
  response.responseText.evalScripts();
}

Or, better, just to be safe if you have long-running scripts:

function submit_update(response) {
  var body = response.responseText;
  body.evalScripts.bind(body).defer();
}

-Fred

On Tue, Jun 10, 2008 at 7:51 AM, marius@thehendonmob.com <
marius@thehendonmob.com> wrote:

>
> The form is submitted properly and submit_update function is called
> upon completion. The thing is that the returned html code contains
> javascripts which should be evaluated and I simply can't force
> prototype to do this. I tried evalScripts: true but it doesn't work.
> Any ideas? Thanks.
> >
>


--
Science answers questions; philosophy questions answers.
09b36db86f0d97d534b9f5a6fea7deb1?d=identicon&s=25 marius@thehendonmob.com (Guest)
on 2008-06-10 16:40
(Received via mailing list)
Thanks. This is exactly what I needed.
This topic is locked and can not be replied to.