2012-02-01 12 views
1

Uploadifyを使用した後にJSONデータを返すときに問題が発生しました。json戻りデータがIEまたはChromeで機能しない

このコードはFirefoxでは動作しますが、IE 9やGoogle 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();それはInternet Explorer、少なくとも古いものでは動作しないので、良い選択ではない、それはかなり悪いと考えられている。あなたはより多くの情報については、各

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

とそれを介してJSONオブジェクトとして、その代わりにeval、ちょうどループの応答を得るでしょう

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

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

これをチェックしてくださいそれぞれチェックアウトするhttp://api.jquery.com/each/

+0

これはIEやChromeではまだ動作していません。 – Steven

関連する問題