我使用jquery表单插件上传文件并在回调中获取HTML(或文本或任何内容)。
这个工作正常,直到1.5,但是一旦我转换为1.5,只有在表单中选择了一个文件时才会发生回调。如果不是,则回调发生,我的代码正常启动。这是非常奇怪和非常具体的,因为它从未发生在1.4,我认真控制记录和调试每行代码。
以下是JS代码示例:
var options= {
dataType:'html',beforeSubmit:function() {
$(field).val(filePath);
loaderdisplay("show");
$("#reuploadDocumentDialogForm").hide();
},
url:actionurl, // the url containing the below function
type:"POST",
success:function(responseText, statusText)
{
// If $_FILES was empty, the last IF fires. If not, NOTHING happens.
console.log(responseText);
console.log(statusText);
if (responseText=='success-1')
{
loaderdisplay("hide");
reportStatus(1, "Successfully reuploaded file.");
$("#reuploadDocumentDialogForm").css("display","inline");
$("#reuploadDocumentDialog").dialog('close');
}
else if (responseText=='success-0')
{
loaderdisplay("hide");
reportStatus(0, "There was an error.File was not uploaded.");
$("#reuploadDocumentDialogForm").css("display","inline");
}
else if (responseText=='error uploading file')
{
loaderdisplay("hide");
reportStatus(0, "File was not uploaded.Try to make the file size smaller.");
$("#reuploadDocumentDialogForm").show();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// THIS NEVER EVER HAPPENS regardless of what I do
alert(textStatus+" - There was an error submitting the form: "+errorThrown);
}
};
$('#reuploadDocumentDialogForm').ajaxForm(options);
以下是PHP代码段示例:
public function reuploaddocumentAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
if (!empty($_FILES))
{
$tempFile = $_FILES['reuploadDocumentDialogFormFile']['tmp_name'];
$targetFile = $this->_getParam("reuploadDocumentDialogFormTargetFile");
$result = move_uploaded_file($tempFile,$targetFile);
die('success-'.$result);
}
else
{
die('error uploading file');
}
}
我试过返回die(json_encode(array(“success”=> $ result)));同样(并将表单选项中的dataType更改为JSON,我尝试将dataType更改为文本,并将die留作字符串。没有任何作用 - 如果我在jQuery1.5上,我根本无法输入成功回调并且选择了一个文件。如果没有选择文件,它会很好地输入。
另外值得注意的是:文件上传好了!我只是永远不会进入回调! 有任何想法吗?感谢
答案 0 :(得分:0)