dtgv52982 2014-07-09 12:29
浏览 11

图像未上传到目录中

I have an option to upload images with caption for every table and there can be any number of tables.

I am using the script below but alert('qwert') does not popup but instead alert('asdf') popsup.Any ideas?

PHP file1:

<form  method='post' enctype='multipart/form-data' class='MyUploadForm'>
                    <input name='ImageFile' class='imageInput' id='imageInput' type='file'>
                    <input class='form-control dsa addcaption' name='addcaption' placeholder='Add caption' type='text' >
                    <input type='submit'  class='btn-custom5' value='Upload' >
                    <button class='btn btn-custom4 imageuploading' name='imageuploading' style='visibility:hidden' value='$x' ></button>//$x will specify path
                    </form>
                    <div class='output'></div>

AJAX:

$(document).ready(function() { 
    var options = { 
            target:   '.output',   // target element(s) to be updated with server response 
            beforeSubmit:  beforeSubmit,  // pre-submit callback 
            success:       afterSuccess,  // post-submit callback 
            resetForm: true        // reset the form after successful submit 
        }; 

     $('.MyUploadForm').submit(function() { 
            $(this).ajaxSubmit(options); 
            return false; 
        }); 

}); 


function beforeSubmit(){
 alert('qwert');
//code to check conditions for file type and size
}

PHP file2:

if(isset($_POST))
{
    //check if this is an ajax request
    if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
        die("<script> alert('asdf')</script>");
    }
}
  • 写回答

2条回答 默认 最新

  • dongpan1308 2014-07-09 12:48
    关注
    $(document).ready(function() {
    
    var request = $.ajax({
        url: $('.MyUploadForm').attr('action'),
        type: "POST",
        dataType: "html",
        target:   '.output',   // (Not sure about this) target element(s) to be updated with server response
        beforeSend:  beforeSubmit,  // pre-submit callback 
        success:       afterSuccess,  // post-submit callback 
        resetForm: true        // reset the form after successful submit 
    }); 
    
    function beforeSubmit(){
       alert('qwert');
       //code to check conditions for file type and size
    }
    

    Hopefully, I'm right. You can check the jQuery.ajax API for more.

    EDIT:

    I'm not sure about target. Maybe you should set the targets in success callback.

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题