Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript and AJAX question
Old 09-04-2007, 01:12 AM Javascript and AJAX question
Junior Talker

Posts: 1
Trades: 0
In AJAX, I need to return several javascript functions which are called by event handlers in the http response. However, I cannot get those javascript functions evaluated by the browser.
For example, if server returns the following for an AJAX request:
<script>
function foo()
{
}
<script>
<form>
<input type='button' value='test' onclick='foo()'> </form>
I can see the 'test' button, but when I click it, I got error: "foo() not defined".
I searched on google and found people suggested using eval(), but that doesn't work for function either.
jessiema is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-04-2007, 01:34 AM Re: Javascript and AJAX question
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
You didn't close your <script tag in that sample.

Alternatively, I find that <form onsubmit="return foo()"> works the best.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 09-06-2007, 10:50 PM Re: Javascript and AJAX question
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Javascript returned by an AJAX request (ie. in req.responseText) will not be evaluated. Even if you use innerHTML on an element to change it's contents, it still won't be evaluated.

You need to use regex to fetch the code between the <script></script> tags and then use eval() to evaluate it. Much easier to use a JS framework to do AJAX, though. For example, jQuery's AJAX methods will automatically evaluate JS form the server when you set the dataType option to 'html'.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript and AJAX question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21330 seconds with 12 queries