【发布时间】:2026-02-12 16:55:02
【问题描述】:
我在使用 cakePHP 设置文件上传元素以在表单中使用时遇到问题,并且 ajaxSubmit() 函数不发送 ajax 请求。我的代码如下,任何想法表示赞赏
在另一个元素中,我也非常成功地使用 .ajaxForm() 方法上传文件。
<script>
$(document).ready(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('#frmFileForm1').ajaxForm({
url: 'http://up.dev/admin/pages/file',
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
reloadfilemanager();
}
});
var options = {
url: 'http://up.dev/admin/pages/file',
iframe: true,
type: 'post',
target: '#status',
data: 'submitBtn'
}
$('button').click(function() {
$('#frmFileForm1').ajaxSubmit(options);
alert("AA");
});
});
</script>
<div>
<?php
//<!-- form for uploading file -->
echo $this->Form->button('Upload File', array( 'name' => 'submitBtn', 'class' => 'btn_submit', 'style' => 'margin-top: 5px; margin-bottom: 5px;', 'type' => 'submit'));
?>
</div>
【问题讨论】:
标签: php jquery ajax cakephp jquery-forms-plugin