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をテキストに変更して、ダイを文字列のままにしてみました。何も機能しません-jQuery1.5を使用している場合、成功のコールバックを入力できませんAND a file was selected. ファイルが選択されていない場合でも問題なく入力されます。
また、注目に値する: ファイルは正常にアップロードされます! 私はコールバックに入ることはありません!何か案は?ありがとう