Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic