2014-03-07 5 views
0

[This] [1]은 내 json 파일의 링크이며 해당 데이터를 내 Ajax 성공 함수에 액세스하려고합니다. 내가 어떻게 할 수 있니?주어진 json 파일에서 데이터를 가져 오는 방법

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

실제 문제는 무엇입니까? –

+0

내 문제는 내가 주어진 URL – user3291749

+0

에서 데이터에 액세스하려는 것이고 사용자가 다른 이야기를 클릭하면이 loid가 변경됩니다. – user3291749

답변

0

문제는 개체 응답이 때문이다 : 당신은 당신이 d["http://www.livemint.com/template/..."]

을해야 할 것 d.data 말할 수 없습니다

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

하지만 당신은 다음과 같이 수행 할 수 있습니다

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); 
     } 
}) 

여기가 작동하는 바이올린입니다. http://jsfiddle.net/cA396/

+0

그래, 우리가 d.data를 말할 수 없다. 그래서 내가 왜 이렇게 혼란스러워하는지. 당신은 선하고 고맙습니다. – user3291749

+0

정답이면 답으로 표시해주세요. :-) – TryingToImprove

관련 문제