ajaxForm不回呼 [英] ajaxForm not callingBack

查看:82
本文介绍了ajaxForm不回呼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道很多人已经在数百篇文章中谈到了这一点,但是我没有看到有人遇到像我这样的问题.

I know that this is already covered by a lot of you and in hundreds of posts but I didn't see anyone with a problem like I'm having.

我正在尝试实现AjaxForm来上传文件.我阅读了所有教程,文档,示例……所有内容.

I'm trying to implement the AjaxForm to upload files. I read all the tutorials, documentation, examples ... everything.

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文件已被调用,并且还可以看到在几毫秒后,响应为"200 OK",并且可以看到由php发送的HTML.

When I submit the form, the ajaxForm is called, on fireBug I can see the php file been called and I can also see that the response is '200 OK' after a few 'ms' and I can see the response in HTML sent by the php.

问题是响应后未触发任何成功"或错误",该表单未重置...好像没有回调.

The problem is after the response no 'success' or 'error' is triggered, the form is no reseted ... looks like there is no callback.

有人可以告诉我我在做什么错吗? PHP中的"echo"是否必须采用某些特定格式?我正在向jQuery发送一个简单的"File:image.jpg(7487字节)".

Can anyone tell me what I'm doing wrong? Does the 'echo' from the php has to be in some specific format? I'm sending a simple "File: image.jpg (7487 bytes)" back to the jQuery.

致谢.

推荐答案

这是ajaxFrom的小示例,它也返回回调事件:

here is the small example of ajaxFrom that return the callback event as well:

<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:

now working with 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在行动.

the purpose of implementing the ajaxFrom here to submit the image without click event, and in the above jquery codes, i have attached the event on Change, the form is submitted automatically and call the get_img.php which is in action.

target上,您将通过文件get_img.php
获得返回的内容 然后在success上设置所需的任何回调方法.

on the target you get what you have returned through the file get_img.php,
and on success you set any callback, method that you want.

这篇关于ajaxForm不回呼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆