为什么我的 ajax mootools 方法不断向我显示错误警报?
我正在尝试制作一个简单的上传文件系统,这是我的代码,我希望你能帮助我,帮助非常感谢
init.php
<form method="post" action="" enctype="multipart/form-data">
<label for="file">Upload a file</label>
<input type="file" name="file" id="fileArchivo" />
<input type="submit" name="submit" id="btnUpload" value="Upload file" />
</form>
Ajax mootools方法
window.addEvent("domready",function(){
cargarIndex();
});
function loadIndex()
{
var Request = new Request({
method: 'POST',
url: '../CONTROLLER/init.php',
onRequest: function() {},
onSuccess: function(text, xmlrespuesta){
document.getElementById('archive').innerHTML= texto;
$('btnUpload').addEvent('click',function(){uploadFile()});
},
onFailure: function(){alert('Error!');}
}).send();
}
function uploadFile(){
//$('btnUpload').addEvent('click', function(){
alert('in');
archivo = $('fileArchivo').value;
alert(archivo);
var nuevoRequest = new Request({
method: 'POST',
data: 'archivo='+archivo,
url: '../CONTROLLER/controllerSave.php',
onRequest: function() {$('subirarchivo2').innerHTML="Cargando...";},
onSuccess: function(texto, xmlrespuesta) {$('subirarchivo2').set('html',texto);},
onFailure: function(){alert('Error!');}
}).send();
//});
}
Firebug说未捕获的异常:
[异常...“提示由用户中止”nsresult:“0x80040111 (NS_ERROR_NOT_AVAILABLE)”位置:“JS框架:: 资源://gre/components/nsPrompter.js :: openTabPrompt ::第468行” 数据:无]
但我没有得到答案,我已经搜索但什么也没有,错误警报位于 uploadFile 中的 onFailure 中。
I am trying to make a simple upload file system, and this is my code , I hope you can help me, help very appreciated
init.php
<form method="post" action="" enctype="multipart/form-data">
<label for="file">Upload a file</label>
<input type="file" name="file" id="fileArchivo" />
<input type="submit" name="submit" id="btnUpload" value="Upload file" />
</form>
Ajax mootools method
window.addEvent("domready",function(){
cargarIndex();
});
function loadIndex()
{
var Request = new Request({
method: 'POST',
url: '../CONTROLLER/init.php',
onRequest: function() {},
onSuccess: function(text, xmlrespuesta){
document.getElementById('archive').innerHTML= texto;
$('btnUpload').addEvent('click',function(){uploadFile()});
},
onFailure: function(){alert('Error!');}
}).send();
}
function uploadFile(){
//$('btnUpload').addEvent('click', function(){
alert('in');
archivo = $('fileArchivo').value;
alert(archivo);
var nuevoRequest = new Request({
method: 'POST',
data: 'archivo='+archivo,
url: '../CONTROLLER/controllerSave.php',
onRequest: function() {$('subirarchivo2').innerHTML="Cargando...";},
onSuccess: function(texto, xmlrespuesta) {$('subirarchivo2').set('html',texto);},
onFailure: function(){alert('Error!');}
}).send();
//});
}
Firebug says that uncaught exception:
[Exception... "prompt aborted by user" nsresult: "0x80040111
(NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
resource://gre/components/nsPrompter.js :: openTabPrompt :: line 468"
data: no]
But I dont get the answers, I already search but nothing, the Error alert is in the onFailure in the uploadFile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不能像这样使用ajax上传文件。
http://mootools.net/forge/p/form_upload 作者:核心成员 Arian
http://mootools.net/forge/p/uploadmanager 作者:Thiery Bela
两者都提供通过 HTML5 界面提供明智的解决方案,并为旧版浏览器提供 Flash 上传器回退/降级功能。
can't use ajax like so to upload files.
http://mootools.net/forge/p/form_upload by core member Arian
http://mootools.net/forge/p/uploadmanager by Thiery Bela
Both provide sensible solutions via HTML5 interfaces with a flash uploader fallback / degradation for older browsers.