0
<script type="text/javascript>
function loadmemberg(m)
{
   $.ajax({
   type   : "POST",
   url    : "details.php",
   data   : {gvalue:m},
   success: function(data){
   var obj = $.parseJSON(data);
         $('#name').val(obj[0].FullName);
         $('#place').val(obj[0].PlaceName);
   var obj="";
         },
   error: function(data){
   alert("Please Enter a valid details");  
   }
   }); 
}
</script>
<html>
<div><input type="text" id="name"/></div>
<div><input type="text" id="place"/></div>
<div><img src="" id="image"></div>
</html>

This is my code and i want to get my image filename from the json object and display it in the html How can i do it...?

1 Answer 1

1

First of all your JSON object must contain image filename that you want to display. Then to set the src attribute value you should add this code to success function:

$("#image").attr("src", obj[0].ImageFileName);
Sign up to request clarification or add additional context in comments.

4 Comments

Welcome to StackOverflow! Can you be more specific of how your code can help the original poster?
How to include the image path...? My images are stored in image folder
thanx a lot, it worked for me...$("#image").attr("src", "../../images/" + obj[0].PhotoFileName);
Hey i have one more question. Initially my <div style="display:none"><img src="" id="image"></div>. I want to change the style display to show/block when the name is entered. How can i do this in JSON....? I tried $("#image").show(); But it is not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.