• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Script in AJAX response

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a problem with JavaScript embedded in my AJAX response.

I have declared a Javascript variable "test" in my AJAX response. I am also creating a button in the response. On clicking this button, I want to alert "test".

I get the response correctly. I verified this using Firebug. However, when I click on the button, I get an error message "test is undefined". Any idea why this would happen?

I tried using

e v a l()

as suggested in another thread here, but that did not seem to work either.

Do I need to set the response type to anything specific?
Am I missing something here?

Any help would be appreciated.

This is my HTML code


This is my servlet code ....

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would have to strip out the script and eval the JavaScript. Easiest thing to do is look into using Prototype.js or JQuery which has it built into their Ajax calls.

Eric
 
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic