Jquery ajax 表单提交响应自动收到警报



我正在尝试使用ajax表单上传图像。图片上传成功。但是 ajax 响应会自动发出警报,并显示一个空白弹出窗口,上面写着"www.xxx.com 的页面说"。

这是我的jQuery代码

$('#profileImg').die('click').live('change', function()         
{
$("#profileform").ajaxForm({target: '#preview_profile', 
 beforeSubmit:function(){ 
 $("#profileloadstatus").show();
 $("#profileloadbutton").hide();
 }, 
success:function(s){
 $("#profileloadstatus").hide();
 $("#profileloadbutton").show();
}, 
error:function(){ 
 $("#profileloadstatus").hide();
 $("#profileloadbutton").show();
 $('#profileform').reset();
} }).submit();
if(!s)
{
    $("#profileform")[0].reset();
}
});

网页表单

<div id="preview_profile"></div><form id="profileform" method="post" enctype="multipart/form-data" action='message_profile_ajax.php'>
                    <div id="preview_prof"></div>
                    <div id="profileloadstatus" style="display:none; text-align:center;">
                                    <img src='images/wall_icons/ajaxloader.gif'/> Uploading....
                                    </div>
                     <div id="profileloadbutton">               
                     <input type="file" id="profileImg" name="profileImg">
                     </div>
                     <input type="hidden" id="profvalues" value=""  />
                     </form>

菲律宾代码

<?php
include_once 'includes.php';

function getExtension($str) 
 {
     $i = strrpos($str,".");
     if (!$i) { return ""; } 
     $l = strlen($str) - $i;
     $ext = substr($str,$i+1,$l);
     return $ext;
 }
 function getImangeName($str) 
 {
     $i = strrpos($str,".");
     if (!$i) { return ""; } 
     $l = strlen($str) - $i;
     $ext = substr($str,0,$i-1);
     return $ext;
 } 
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
    {
        $name = $_FILES['profileImg']['name'];
        $size = $_FILES['profileImg']['size'];
        if(strlen($name))
            {
                 $ext = getExtension($name);
                 $imageName = getImangeName($name);
                if(in_array($ext,$valid_formats))
                {
                if($size<(1024*1024))
                    {
                        $actual_image_name = $imageName.time().$uid.".".$ext;
                        $tmp = $_FILES['profileImg']['tmp_name'];
                        if(move_uploaded_file($tmp, $profile_path.$actual_image_name))
                            {
                                 $data=$Wall->Profile_Image_Upload($uid,$actual_image_name);
                                 if($data)
                                {
                                     echo '<img src="'.$profile_path.$actual_image_name.'" class="img-circle" alt="User Image" />';
                                }
                            }
                        else
                         {
                            echo '<b>Sorry, </b>Falied to upload your file!';
                         }
                    }
                    else
                    echo '<b>Sorry, </b>Image file size must be less than 1 MB!';
                    }
                    else
                    echo '<b>Sorry, </b>Invalid file format!';  
            }
        else
            echo '<b>Sorry, </b>Please select image..!';
        exit;
    }

?>

请帮忙,

谢谢

Check jquery.wallform.js

        //return data;
        // Modification www.9lessons.info
        var exp = /<img[^>]+>/i;
        expResult = data.match(exp);
        if(expResult == null) {
            alert(data);
        } else {
            $(options.target).prepend(data);
        }
       $("#photoimg").val('');
       // Modification End www.9lessons.info

最新更新