惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
T
Threatpost
C
CERT Recently Published Vulnerability Notes
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
Project Zero
Project Zero
H
Heimdal Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News | PayPal Newsroom
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
L
LINUX DO - 热门话题
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
V
Vulnerabilities – Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
S
Securelist
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
NISL@THU
NISL@THU
N
News and Events Feed by Topic
S
Security Affairs
The Last Watchdog
The Last Watchdog
T
Tor Project blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security

博客园 - 天天无用

jsonp原理实例及mvc中的应用 ubuntu笔记 修复MVC3中使用Remote验证的一点小问题 诺基亚手机S60系统证书申请、软件签名图文教程 JAXER留言板-一个html页面的ajax留言版 - 天天无用 - 博客园 初探JAXER 本月wii游戏太多,感觉有点堕落 使用jQuery加DIV实现可以动态添加的金字塔结构 自制的操作下拉列表框(SELECT)的三个jquery插件(ajax填充、联动、增加选项) - 天天无用 - 博客园 Asp.net 2.0 TreeView控件使用jQuery无刷新添加节点详细说明 用jQuery实现.net 2.0 treeview客户端无刷新操作的实例 基于jQuery的AJAX和JSON实现纯html数据模板 自己写的DataTable转换成JSON字符串的函数 自己写的jQuery自动完成的插件(AutoComplete) asp.net treeview控件无刷新选择和删除节点(使用jquery) - 天天无用 - 博客园 纵向合并gridview单元格的两种方法 .net下两种json序列化速度比对 asp.net 2.0 中 TreeView控件中的checkbox客户端操作 asp.net 2.0中根据roles显示不同的sitemap - 天天无用 - 博客园
Jquery插件研究:Ajax File Upload
天天无用 · 2007-11-15 · via 博客园 - 天天无用

    今天开始研究Jquery的官方插件,首先是Ajax File Upload插件,网站地址在这里http://www.phpletter.com/DOWNLOAD/,其中还有其他的javascript file/image manager,以后再研究吧。

    看了一下它的Demo,做的很简单,服务器端是用php写的,我改成用.net写了,主要代码:

        $.ajaxFileUpload
        (
            
{
                url:'doUpload.aspx',
                secureuri:
false,
                fileElementId:'fileToUpload',
                dataType: 'json',
                success: 
function (data, status)
                
{
                    
if(typeof(data.error) != 'undefined')
                    
{
                        
if(data.error != '')
                        
{
                            alert(data.error);
                        }
else
                        
{
                            alert(data.msg);
                        }

                    }

                }
,
                error: 
function (data, status, e)
                
{
                    alert(e);
                }

            }

        )

    说明一下主要参数,url用来指定后台处理的程序,secureuri暂时不太明白(后面还会说道),fileElementId指的是文件选择框的ID,dataType用来指定返回的数据格式,支持xml、script、json和html。返回的json的格式最简单:{error:'errormsg',msg:'successmsg'},看后台代码就明白了。success为上传成功后执行的function,其中的data参数就是服务器端返回的参数。error当然就是上传失败后执行的function,其中参数e为javascript捕获的错误。status参数一般用不到,上传成功是值为"success",失败时一般为"timeout"。

    ajax上传的原理也不是很复杂,这部分代码执行的时候,会创建一个用来上传文件的

from和一个用来接收返回值的Iframe,生成的html代码如下:

<form target="jUploadFrame1195056805390" style="position: absolute; top: -1200px; left: -1200px;" action="doUpload.aspx" method="post" name="jUploadForm1195056805390" id="jUploadForm1195056805390" enctype="multipart/form-data"><input id="jUploadFile1195056805390" size="45" name="fileToUpload" type="file"></form><iframe style="position: absolute; top: -1000px; left: -1000px;" name="jUploadFrame1195056805390" id="jUploadFrame1195056805390"></iframe>


    可以看到生成的form的action属性就是上面指定的url参数的值,fileElementId指定的文件选择框直接放到这个form中,form的target属性指定的就是生成的iframe的id,这个form提交后返回值就返回到了这个iframe中。上面说的secureuri属性如果指定一个地址的话,这个iframe的src属性就会是这个值,还是不明白有什么用。

    这样就都明白了,其实还是使用原始的方式上传,只不过用javascript把上传和返回的过程都包装了起来,看起来好像页面没有刷新,其实刷新的是页面里面的iframe。

    服务器端的代码很简单,需要说明的是如果返回值有中文的话,需要指定编码为gb2312,我是在web.config里面指定的。还有一点就是ie和firefox上传文件时服务器端得到的文件名不同,ie上传时得到的是上传时的完整路径,firefox上传时只能得到文件名。 

    全部代码请到这里下载http://download.csdn.net/user/luq885/