Reputation: 3217
I have the following ajax call to make a call to webservice and retreive back the json data
$(document).ready(function () {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: "Test.asmx/GetImages",
success: function (msg) {
//var data = JSON.parse(msg);
alert(msg.d);
$.each(msg.results, function (i, tweet) {
alert(msg.d);
$("#imagelist").append('<p><img src="' + tweet + '" />' + tweet + '</p>');
});
}
});
});
I have following json result obtained from the ajax call, I am finding difficult to append the img source .
{"d":"[\r\n {\r\n \"imagepath\": \"images/01.jpg\"\r\n },\r\n {\r\n \"imagepath\": \"images/02.jpg\"\r\n },\r\n {\r\n \"imagepath\": \"images/03.jpg\"\r\n },\r\n {\r\n \"imagepath\": \"images/04.jpg\"\r\n }\r\n]"}
Upvotes: 1
Views: 688
Reputation: 255015
Just specify dataType: 'json'
and jquery will do that automatically for you
http://api.jquery.com/jQuery.ajax/
Upvotes: 5