2012-02-01 4 views
1

Uploadify를 사용한 후 JSON 데이터를 반환하는 데 문제가 있습니다.json 반환 데이터가 IE 또는 Chrome에서 작동하지 않습니다.

이 코드는 Firefox에서 작동하지만 IE 9 또는 Chrome에서는 작동하지 않습니다.
이 Uploadify에 대한 스크립트 스크립트입니다

 jQuery("#uploadify_gallery").uploadify({ 
     'queueID'  : 'fileQueue', 
     'uploader'  : siteURL + '/wp-content/plugins/uploadify/uploadify.swf', 
     'script'   : siteURL + '/wp-content/plugins/uploadify/uploadify_gallery.php', 
     'fileExt'  : '*.jpg;*.jpeg;*.png', 
     'auto'   : true, 
     'multi'   : true, 
     'method'   : 'POST', 
     'buttonImg'  : siteURL + '/wp-content/themes/storelocator/img/buttons/img_upload_grey_bg.png', 
     'cancelImg'  : siteURL + '/wp-content/plugins/uploadify/cancel.png', 
     'queueSizeLimit' : 20, 
     'scriptData'  : {'entity':jQuery('#entity').val(),'entity_id':jQuery('#entity_id').val()}, 
     'onComplete'  : function(event, queueID, fileObj, response, data) { 

      alert('test'); // <-- THIS WORKS 

      //This makes the json response readable 
      var result = eval("(" + response + ")"); 
      alert(result.toSource()); // <-- this never fires 
     }, 
     }); 

이다 내가 uploadify_gallery.php에와 테스트 코드 :

$res = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); 
echo json_encode($res); 

이 어제 일을하고, 나는 그것이

작업을 주 잖아 내가 어떻게이 일을 할 수 있는지에 대한 제안?

+0

평가가 잘못되었습니다. 모든 비용을 들이지 않고 피하십시오. 또한 서버가 스크립트로 반환하는 JSON은 어떻게 생겼을까요? – GordonM

답변

1

서버에서 반환 한 값을 검사하고 유효한 JSON입니다 (예 : JSONLint 사용).

그런 다음 jQuery.parseJSON()을 사용하여 응답 문자열을 개체로 변환 할 수 있습니다.

+0

예, 이걸 발견했는데 지금 사용하고 있습니다. 감사 :) – Steven

0

eval(); 그것은 좋은 선택이 아닙니다. 인터넷 익스플로러에서 작동하지 않을 것이므로, 꽤 나쁜 것으로 간주됩니다. 당신은 JSON 객체로 응답을 얻을 것이다 밖으로

How can I get this eval() call to work in IE?

http://24ways.org/2005/dont-be-eval

이 옵션을 선택합니다, 그래서 대신 평가, 자세한 내용에 대한 각

$(response).each(function(index, value) { 
    console.log(value); 
}); 

와 그것을 통해 단지 루프의 각 체크 아웃 http://api.jquery.com/each/

+0

IE 또는 Chrome에서 아직 작동하지 않습니다. – Steven

관련 문제