0

Valum のファイルアップローダーhttp://valums.com/ajax-upload/を使用しています

以下の index.html はファイルをアップロードし、post.php は json を返します。jsfiddle を作成していなくて申し訳ありませんが、ajax 応答を実装する方法がわかりません。

FF では、responseJSON.icon は

<img src="http://www.tapmeister.com/test/doc.png" width="32" height="32" />

ただし、IE8 では、responseJSON.icon は

<IMG src='"http://www.tapmeister.com/test/doc.png"' width='"32"' height='"32"' >

img が大文字になっていても問題ありませんが、これらの余分な引用符が大混乱を引き起こしています。

これはどのように修正されますか?ありがとうございました

index.html

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="fileuploader.css" rel="stylesheet" type="text/css"> 
    <style>body {font-size:13px; font-family:arial, sans-serif; width:700px; margin:100px auto;}</style>
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script src="fileuploader.js" type="text/javascript"></script>
    <script>        
    $(function(){
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader-demo1'),
            action: 'post.php',
            onComplete: function(id, fileName, responseJSON){
                $('#icons').append('<li>'+responseJSON.icon+' '+$('<span/>').text(responseJSON.icon).html()+'</li>');
            },
            debug: true
        });
    });
     </script>
</head>

<body>      
    <div id="file-uploader-demo1"></div>
    <ul id="icons"></ul>    
</body>
</html>

post.php

<?php
$icon='<img src="http://www.tapmeister.com/test/doc.png" width="32" height="32" />';
$data=array('icon'=>$icon, 'other'=>'other data');
echo(json_encode($data));
?>
4

1 に答える 1

1

post.php で画像の URL を送信してから、javascript で IMG 要素を作成してみませんか?

<?php
echo json_encode(array('icon' => 'http://google.de'));
?>

以下を使用してイメージを作成:

$('<img>').attr('src', responseJSON.icon); //...
于 2012-07-19T16:07:54.280 に答える