jQuery 上传不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1435272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uploadify not working
提问by Graeme
I am using Uploadify and something which was previously working now isn't and I'm not sure why. I get an HTTP error returned whenever I click upload. Watching the net tab in Firefox, it doesn't look like it's even sending anything to the server again.
我正在使用 Uploadify,但以前可以使用的东西现在不能使用,我不知道为什么。每当我单击上传时,都会返回 HTTP 错误。在 Firefox 中查看网络选项卡,看起来它甚至没有再次向服务器发送任何内容。
I've tried putting in the error function to help debug but the status attribute is undefined..
我试过放入错误函数来帮助调试,但状态属性未定义..
$("#fileInput").uploadify({
'uploader': '/scripts/upload/uploadify.swf',
'script': '/Member/UploadImages/PerformUpload',
'cancelImg': '/scripts/upload/cancel.png',
'multi': true,
'simUploadLimit': 1,
'fileDesc': "Images",
'fileExt': "*.jpg;*. jpeg;*.bmp;*.png",
'sizeLimit': 3000000,
'onAllComplete':showFinishedLink,
'onError': function (event, queueID ,fileObj, errorObj) {
var msg;
if (errorObj.status == 404) {
alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
msg = 'Could not find upload script.';
} else if (errorObj.type === "HTTP")
msg = errorObj.type+": "+errorObj.status;
else if (errorObj.type ==="File Size")
msg = fileObj.name+'<br>'+errorObj.type+' Limit: '+Math.round(errorObj.sizeLimit/1024)+'KB';
else
msg = errorObj.type+": "+errorObj.text;
alert(msg);
$("#fileUpload" + queueID).fadeOut(250, function() { $("#fileUpload" + queueID).remove()});
return false;
},
});
Any ideas?
有任何想法吗?
采纳答案by Graeme
OK, figured out that the error debugging I was using was old and that I can say errorObj.info to get out the more detailed info on why it's not working.
好的,发现我使用的错误调试是旧的,我可以说 errorObj.info 以获取有关它为什么不起作用的更详细信息。
Did this and turns out it's a 404 which means the script I'm attempting to POST to isn't being picked up even though it does exist. Sounds like a routing issue...
这样做了,结果发现它是一个 404,这意味着即使它确实存在,我尝试发布的脚本也没有被接收。好像是路由问题...
Case closed!
案件结案!
Just to add more info on this - the 404 was as a result of an old default Login url in the web.config file.
只是为了添加更多信息 - 404 是 web.config 文件中旧的默认登录 URL 的结果。
Once I fixed this, the 404 then became a 302 (looking at the IIS logs) as the site was redirecting me to the login page.
一旦我解决了这个问题,404 就变成了 302(查看 IIS 日志),因为该站点将我重定向到登录页面。
My upload script is in an authenticated area of the site and so I needed to use something which is described in this site
我的上传脚本位于站点的经过身份验证的区域,因此我需要使用本站点中描述的内容
回答by bnieland
I was receiving a 302 error occurring only in Firefox/Chrome: IE8 worked fine. The problem turned out to be that Netscape was now sending auth cookies with it's file postback. I allowed the .ashx file which handled the upload a anonymous authorization in the web config, and had no further problems.
我收到仅在 Firefox/Chrome 中发生的 302 错误:IE8 工作正常。问题原来是 Netscape 现在正在发送带有文件回发的 auth cookie。我允许处理上传的 .ashx 文件在 web 配置中进行匿名授权,并且没有进一步的问题。
<location path="UploadifyUploadHandler.ashx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>