在文件上传器POST响应中获取额外引号

Getting extra quotes in fileuploader POST response

本文关键字:获取 响应 文件 POST      更新时间:2023-12-06

我正在使用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));
?>

为什么不在post.php中发送图像的URL,然后在javascript中构建IMG元素?

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

使用创建图像

$('<img>').attr('src', responseJSON.icon); //...