problem with .html()
i am using this plugin but all works well less one thing. In the example of de开发者_运维百科velopper in the final of upload is showed 3 info about the file I want do something like that.
<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 />
At the moment only the image is uploaded and none message is showed.
The question is, in my php file i test a simple echo that is not showed in .html().
this is the example of the 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);
in my case i just test with a echo "success";
what i am doing wrong?
PS: awesome plugin
Here is few reasons why your application does not work:
$(this).upload('thumb.php', function(res) {$(res).insertAfter(this);}, 'html');
in this case upload sends to function a string element which you are trying to convert to DOMnode, so result of res
suppose to be some html structure like
<li>some text</li>
your php code return JSON string which is treated as simple string by uploader
if you are planning to use JSON formatted response change lasta parameter of $(this).upload();
from 'html'
to 'json'
精彩评论