我知道这已经被你们中的许多人和数百篇帖子所覆盖,但我没有看到任何人有像我这样的问题。
我正在尝试实现上传文件的AjaxForm。我阅读了所有的教程,文档,示例...所有的一切。
HTML:
<form action="scripts/upload_script.php" method='post' id="upload_picture_form" enctype="multipart/form-data">
File: <input type="file" name="upload" id="upload" /></p>
<p><input type="submit" name='submit' value="Submit" /></p>
</form>Jquery:
$('#upload_picture_form').ajaxForm({
success: function(){
alert('success');
},
error: function(){
alert('error');
},
resetForm:true
}); 当我提交表单时,ajaxForm被调用了,在fireBug上,我可以看到调用了php文件,我还可以看到在几个'ms‘之后的响应是’200ok‘,我可以看到由php发送的响应。
问题是在没有‘成功’或‘错误’的响应被触发之后,表单没有被重置...看起来没有回调。
有人能告诉我我哪里做错了吗?来自php的“echo”必须是某种特定的格式吗?我向jQuery发回一个简单的“文件: image.jpg (7487字节)”。
致以问候。
发布于 2012-10-10 16:40:16
下面是返回回调事件的ajaxFrom的小示例:
<form id="imageform" enctype="multipart/form-data" action="get_img.php" method="post">
<tr>
<td valign="top"><label>Select File</label> :</td>
<td><input type="file" name="myfile" id="myfile" /> <br />
<em>.jpeg, .jpg, .gif, .png, .bmp</em>
</td>
</tr>
</form>
<div id="result"></div>现在使用jquery:
$(function(){
$('#myfile').live({
change: function(){
$('#result').ajaxStart(function(){
$(this).html('<div class="loader" />');
});
$('#imageform').ajaxForm({
target: '#result',
success: function(){ // Call Back Function }
}).submit();
}
});
});在这里实现ajaxFrom的目的是在没有点击事件的情况下提交图像,在上面的jquery代码中,我已经在Change上附加了事件,表单自动提交并调用正在运行的get_img.php。
在target上,您将获得通过文件get_img.php返回的内容,
在success上你可以设置任何你想要的回调和方法。
https://stackoverflow.com/questions/12814590
复制相似问题