[英]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()中未顯示的簡單回顯。
這是開發人員的例子
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";
測試echo "success";
我做錯了什么?
PS:很棒的插件
這是您的應用程序無法正常工作的幾個原因:
$(this).upload('thumb.php', function(res) {$(res).insertAfter(this);}, 'html');
在這種情況下,上載會將要轉換為DOMnode的字符串元素發送給函數,因此res
結果應該是一些html結構,例如
<li>some text</li>
您的php代碼返回JSON字符串,如果您打算使用$(this).upload();
JSON格式的響應更改lasta參數,則上傳者會將其視為簡單字符串$(this).upload();
從'html'
到'json'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.