0

[This][1] is the link of my json file and i want to access its data into my ajax success function. tell me how can i do this?

$.ajax({
      type: "GET",
      url: "abc" + imageId,
      dataType: "json",
      success: function (d) {
             alert(imageId);
             var storyImage = d.data;
             alert(storyImage);
      }
 })

2 Answers2

0

Problem is that the object response is:

 {
 "http://www.livemint.com/template/features/webapps/encodeImage?loid=2.1.1521199245": {
     "data":"data:image/jpg;base64,/9j/4AAQSk..."}
}

So you can't say d.data you will have to do d["http://www.livemint.com/template/..."]

But you can do something like this:

var imageId = "2.1.1521199245"
var url = "http://www.livemint.com/template/features/webapps/encodeImage?loid=" + imageId;
$.ajax({
      type: "GET",
      url: url,
      dataType: "json",
      success: function (d) {
              alert(imageId);
             var storyImage = d[url].data;
             alert(storyImage);
      }
 })

Here is a working fiddle: http://jsfiddle.net/cA396/

TryingToImprove
  • 7,047
  • 4
  • 30
  • 39
-1

You need parse JSON into Object http://www.json.org/js.html

If you do a crossdomain request $.ajax will be not work. See jQuery AJAX cross domain

Community
  • 1
  • 1
user1809655
  • 131
  • 6