problem with .html()


problem with .html()

我正在使用这个插件,但所有的工作都很好,少一件事。在开发人员的例子中,最后的上传显示了关于文件的3个信息我也想这样做。

 <script type="text/javascript">
        $(function() {
            $('#userfile').change(function() {
                $(this).upload('thumb.php', function(res) {
                    $(res).insertAfter(this);
                }, 'html');
            });
        });
      </script>
    </head>
    <body>
        <input type="file" name="userfile" id="userfile">
        <br />

目前只有图片上传,没有消息显示。

问题是,在我的php文件中,我测试了一个简单的回显,它没有显示在。html()中。

这是dev

的例子
if (move_uploaded_file($_FILES['yourkey']['tmp_name'], '/path/to/save/' . $filename)) {
    $data = array('filename' => $filename);
} else {
    $data = array('error' => 'Failed to save');
}
header('Content-type: text/html');
echo json_encode($data);

在我的情况下,我只是测试echo "success";

我做错了什么?

PS: awesome plugin

下面是你的应用程序不能工作的几个原因:

 $(this).upload('thumb.php', function(res) {$(res).insertAfter(this);}, 'html');

在这种情况下,upload发送给函数一个字符串元素,您试图转换为DOMnode,所以res的结果应该是一些html结构,如

<li>some text</li>

你的php代码返回JSON字符串,它被上传器视为简单字符串如果您计划使用JSON格式的响应将$(this).upload();的lasta参数从'html'更改为'json'