0
我使用Valum的fileuploader http://valums.com/ajax-upload/獲得在fileuploader POST響應額外的引號
下面的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));
?>
感謝theW0rld。如果這是唯一的解決方案,可能最終會這樣做。 – user1032531 2012-07-19 16:10:40
這回答了這個問題。如果有人知道其他解決方案,請發佈。謝謝 – user1032531 2012-07-20 13:42:47