FW: [jQuery] Re: Returning Javascript

2009-02-17 Thread Sam Fleming

Basically, my ajax loads each page. If i want to put javascript in that page
the javascript does not run. Can i eval the whole response? Html and
everything? Or do i have to filter out the javascript? Maybe it would be
easier to make the jquery load another script in a file? If this is
possible?

-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of James
Sent: 17 February 2009 21:25
To: jQuery (English)
Subject: [jQuery] Re: Returning Javascript


I'm not understanding what you're trying to do.
You just want your AJAX to return Javascript code and have it
executed?

If so, you can use the eval() function, but be careful of the source
of your Javascript.

On Feb 16, 10:30 pm, s.flemin...@googlemail.com
s.flemin...@googlemail.com wrote:
 I am trying to write my first application, and am trying to use jquery
 to help me along my travels.

 I have setup my application to work so all pages are loaded via ajax,
 using anchor's as navigation. However on some pages that i return
 using the AJAX i want to be able to run code.

 This works on firefox, however it does not work on anything else. So
 really my question is:

 How do i run javascript code from an ajax response?

 p
         form action=ajax/forms.php method=post id=myform
         Title: input type=text name=title /
         input type=submit value=Submit name=submit /
     /form
 /p
 script type=text/javascript
 // attach handler to form's submit event
 alert(Javascript);
 $('#myform').submit(function() {
     // submit the form
     alert(form submitted);
     // return false to prevent normal browser submit and page
 navigation
     return false;

 });

 /script

 In the above, i only get an alert saying Javascript in firefox. Any
 other browser and it does not work.

 Please help!



Re: FW: [jQuery] Re: Returning Javascript

2009-02-17 Thread Aaron Gundel

eval is only for javascript.  You cannot eval the whole response.  If
you want to put javascript in other files, it is possible to load them
dynamically at runtime.  See the following for more information about
On-Demand Javascript... It's foundational to several other concepts
floating around on the web, so you'll want to get a handle on it.

http://ajaxpatterns.org/On-Demand_Javascript

On Tue, Feb 17, 2009 at 1:35 PM, Sam Fleming s.flemin...@googlemail.com wrote:

 Basically, my ajax loads each page. If i want to put javascript in that page
 the javascript does not run. Can i eval the whole response? Html and
 everything? Or do i have to filter out the javascript? Maybe it would be
 easier to make the jquery load another script in a file? If this is
 possible?

 -Original Message-
 From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
 Behalf Of James
 Sent: 17 February 2009 21:25
 To: jQuery (English)
 Subject: [jQuery] Re: Returning Javascript


 I'm not understanding what you're trying to do.
 You just want your AJAX to return Javascript code and have it
 executed?

 If so, you can use the eval() function, but be careful of the source
 of your Javascript.

 On Feb 16, 10:30 pm, s.flemin...@googlemail.com
 s.flemin...@googlemail.com wrote:
 I am trying to write my first application, and am trying to use jquery
 to help me along my travels.

 I have setup my application to work so all pages are loaded via ajax,
 using anchor's as navigation. However on some pages that i return
 using the AJAX i want to be able to run code.

 This works on firefox, however it does not work on anything else. So
 really my question is:

 How do i run javascript code from an ajax response?

 p
 form action=ajax/forms.php method=post id=myform
 Title: input type=text name=title /
 input type=submit value=Submit name=submit /
 /form
 /p
 script type=text/javascript
 // attach handler to form's submit event
 alert(Javascript);
 $('#myform').submit(function() {
 // submit the form
 alert(form submitted);
 // return false to prevent normal browser submit and page
 navigation
 return false;

 });

 /script

 In the above, i only get an alert saying Javascript in firefox. Any
 other browser and it does not work.

 Please help!