Question

Hi i am sending this json to jsp which contain file url i want to display image by this url in ajax. can any one help me.

 //controller
  recordingInfo = recordingManager.getRecordingInfo(new Integer(recordingId));    

 map.put("status", true);    

 map.put("recordingInfo", recordingInfo);  

 return JSONSerializer.toJSON(map).toString();    

Here i am sending json object to jsp and trying to get by ajax call as follows. this json contains url like

  d:/abc/xyz.jpg

i want to display it as image when i clicked on that url. how can i do that.

//jsp

 function showUploadedImages(recordingId) {
    $("#recordingId").val(recordingId);
    $("#newRecording").hide();
    $.ajax({
        type : 'POST',
        url : 'adminShowUploadedImages',
        data : ({
            recordingId : recordingId
        }),
        success : function(data) {
            var returnData = jQuery.parseJSON(data);
            if (returnData.status) {
                alert(returnData);
        });

in returnData i have url i want to display it as image. help me

Was it helpful?

Solution

  1. put a div in a body with attribute id picture e.g. <div id="picture"></div>
  2. append img tag to the div

example

//code
success : function(data) {
      var returnData = jQuery.parseJSON(data);           
      $("#picture").append("<img src=\" + returnData.img_url + "\" />");
});
//code if any
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top