什么是错我的劣质AJAX文件上传? [英] What is wrong with my Flimsy AJAX File Upload?

查看:110
本文介绍了什么是错我的劣质AJAX文件上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道你不能做一个AJAX文件上传但是这只是一个名字,我选择使用。 :)

I know you can not do an AJAX File Upload but this just a name I have chosen to use. :)

我利用这个jQuery插件。我认为主要的问题是我使用它在一个稍微不同的背景。这是我如何使用它,我觉得这是问题。

I am making use of this JQuery plugin. I think the main problem is I am using it in a slightly different context. Here is how I use it and I think this is the problem.

我第一次做一个表格:

$("#flash").html("<input id='vidup' type='file' name='file' size='10' /><input type='button' name='submit' onclick='videoUpload();' value='Upload' />");

我按一下按钮将调用这个函数videoUpload使一个AJAX请求得到一个变量,它是上传的URL,这是动态创建的:

I click on the button will call this videoUpload function which makes an AJAX request to get a variable which is the URL to upload to, this is dynamically created:

function videoUpload(){
    $.get("getUploader.php", function(data){
    new AjaxUpload('#vidup', {
    	  action: data,
    	  name: 'myfile',
    	  responseType: 'xml',
    	  onSubmit: function() {
    	    // allow only 1 upload
    		alert('onSubmit' + data);
    	    this.disable();
    	  },
    	  onComplete: function(file, response){
    		  alert('Response' + response);
    	  }
    	});
    });
}

不过,这种情况发生的唯一的事情是,隐藏字段创建名为myfile的',但我没有提醒现身!该插件的创建者是通过$(文件)。就绪(函数(),利用它,我不是,这将导致一个问题?

However, the only thing that happens is that hidden field is created titled 'myfile' but none of my alerts show up! The creator of the plugin is making use of it via the "$(document).ready(function()" and I am not, will this cause a problem?

请提问,因为我不知道给什么其他的信息!

Please ask questions as I do not know what other info to give!

感谢所有

它管理与此标记添加输入字段:

It manages to add the input field with this markup:

    <input type="file" name="myfile" style="margin: -5px 0pt 0pt -175px; 
padding: 0pt; position: absolute; width: 220px; height: 30px; font-size: 14px; 
opacity: 0; cursor: pointer; display: none; z-index: 2147483583;"/>

但是,它不会继续上传的文件。我认为它应该也创造了一个iFrame?

However, it doesn't proceed to upload the file. I thought it should have also created an iFrame?

推荐答案

现在的问题是,该插件被注册在准备()的时间。当时你#flash格是空的。您可以修改插件可能结合调用其它事件,但这不是一个很好的主意,或刚刚创建的div从PHP在那里当准备好()被调用。同样的事情发生在我身上的ThickBox的插件。我真的不认为这是对插件开发者注册在准备行动()的很多内容是个好主意,可事后产生的。

The problem is that the plugin is registered at ready() time. At that time your #flash div is empty. You can modify the plugin probably binding the call to other event, but this is not a very good idea, or just create the div from php to be there when ready() is called. The same thing happen to me with the Thickbox plugin. I dont really think is a good idea for plugin developers to register actions at ready() as a lot of content can be generated afterwards.

这篇关于什么是错我的劣质AJAX文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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