Javascript to call jsp, return JSON

Hi there:

I am trying to create a dynamic web page which has 1 dropdown with a few options, one submit button and some place for an image.
I have another application running on a server that I want to execute to return a JSON object to the webpage - the JSON will have the URL of the image that needs to be displayed.

I want help with 2 things:
a. Something on the client that will invoke a JSP or something on the server that will return the JSON
b. What are my options for serverside scripting? My app is deployed on Websphere.

Attached is sample code from the html
javascript-try.html
mightyestmeAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
You need Ajax - I also suggest jquery
Million of good examples on the web

I  now on my iPhone so not easy to see the source of your code but something like
$(function(){
  $("#sel").on("change",function() {
    $.get("somephp",function(data) {
      $("#someimg").attr("src",data.url):
    });
  });
});
0
 
mightyestmeAuthor Commented:
I am new to Ajax - can I return a JSON from my servlet and the javascript will be able to extract parameters I want? Or should I be returning only the attributes I want to javascript to have access to?
0
 
Michel PlungjanIT ExpertCommented:
If you return
{"url":"image.gif"} the code I gave should work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.