当前位置: 代码迷 >> Ajax >> 关于ajaxFileUpload插件的几个小问题
  详细解决方案

关于ajaxFileUpload插件的几个小问题

热度:550   发布时间:2013-10-23 11:39:13.0
关于ajaxFileUpload插件的几个问题!
本帖最后由 LZOMLZOM 于 2013-10-11 22:52:06 编辑
我刚刚学习使用ajaxFileUpload插件,有两个问题如下,求教!

一、网上找到的例子中ajaxFileUpload的参数为什么分为两种?
    1、第一种,类似于如下语句
      

         url:'fileUploadAction.action',//用于文件上传的服务器端请求地址
                secureuri:false,//一般设置为false
                fileElementId:'file',//文件上传空间的id属性  <input type="file" id="file" name="file" />
                dataType: 'json',//返回值类型 一般设置为json
                success: function (data, status)  //服务器成功响应处理函数
                {
                    alert(data.message);//从服务器返回的json中取出message中的数据,其中message为在struts2中action中定义的成员变量
                    
                    if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                            alert(data.error);
                        }else
                        {
                            alert(data.message);
                        }
                    }
                },
                error: function (data, status, e)//服务器响应失败处理函数
                {
                    alert(e);
                }
            }
        )
      

   2、第二种,类似于如下语句:
      


    new AjaxUpload('#upload_button_id', {
    action: 'upload.php',
    name: 'userfile',
    data: {
    example_key1 : 'example_value',
    example_key2 : 'example_value2'
    },
    autoSubmit: true,
    onChange: function(file, extension){},
    onSubmit: function(file, extension) {},
    onComplete: function(file, response) {}
    });
      


我就很奇怪,第一种请求页面用的语句是“url”,怎么第二种就是“action”?还有指定id的语句,第一个是“fileElementId”,第二个是“name”;还有第一个有返回值语句“datetype”,第二个没有!还有其他很多不同,请帮忙解释一下这个插件这两种写法为什么不同,都有什么意义!

二、在第一种写法中,function (data, status) 和function (data, status, e)中的“status”指的是什么?有什么意义?
    在第二种写法中,onSubmit: function(file, extension) {} 中的有如下的例子:
   

   
    var button = $('#button1'), interval;
    new Ajax_upload(button,{
    action: 'upload-test.php',
    name: 'myfile',
    onSubmit : function(file, ext){
    button.text('Uploading');
    this.disable();
    interval = window.setInterval(function(){
    var text = button.text();
    if (text.length < 13){
    button.text(text + '.');
    } else {
  相关解决方案