页面无刷新Upload File
页面无刷新Upload File。
利用jquery.form.js的ajaxForm提交文件。
具体参考以下代码:
前台html
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="form_fileUpload.aspx.cs" Inherits="jq_form_plug.form_fileUpload" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form插件提交文件表单
</title>
<script src="Script/jquery-1.12.3.min.js"></script>
<script src="Script/jquery.form.js"></script>
<script type="text/javascript">
$(function () {
var options = {
success: function (data) {
alert("I am here!!");
$("#responseText").text(JSON.stringify(data));
}
}; $("#form1").ajaxForm(options);
});
</script>
</head>
<body>
<form id="form1" action="ajaxOperation.ashx" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>附件名字:</td>
<td>
<input type="text" name="fileName" /></td>
</tr>
<tr>
<td>附件:</td>
<td>
<input type="file" name="document" /></td>
</tr>
<tr>
<td colspan="2" style="align-content: center">
<input type="submit" value="模拟iframe提交表单" />
</td>
</tr>
</table>
</form>
<br />
<span>需要在ajaxOperation.ashx文件中对ActionName是formUpload的操作进行断点观察</span>
<br />
<br />
<label id="responseText"></label>
</body>
</html>
Handler ajaxOperation.ashx.cs
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Web;
using Newtonsoft.Json; namespace jq_form_plug
{
/// <summary>
/// ajaxOperation
/// </summary>
public class ajaxOperation : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
NameValueCollection frmCol = context.Request.Form;
string actionName = context.Request.QueryString["Action"]; HttpPostedFile file1 = context.Request.Files["document"];
if (file1 != null)
{
//context.Response.Write("文件已上传");
context.Response.ContentType = "application/json";
context.Response.Write("[{\"Title\":\"学习使用AJAX技术\",\"Url\":\"#\",\"ArticleId\":\"Art1234\"},{\"Title\":\"使用JQuery构建网站\",\"Url\":\"#\",\"ArticleId\":\"Art1235\"},{\"Title\":\"使用JSON文件传输数据\",\"Url\":\"#\",\"ArticleId\":\"Art1236\"}]");
}
else
{
context.Response.Write("没有指定文件");
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}
页面无刷新Upload File的更多相关文章
- Ajax下载文件(页面无刷新)
说明:Ajax是无法实现文件传输的,本文只是模拟了Ajax不刷新页面就可以请求并返回数据的效果.实质上还是通过提交form表单来返回文件流的输出. 分步实现逻辑: ajax请求服务器,访问数据库,根据 ...
- 基于jQuery的ajax系列之用FormData实现页面无刷新上传
接着上一篇ajax系列之用jQuery的ajax方法向服务器发出get和post请求写,这篇主要写如何利用ajax和FormData实现页面无刷新的文件上传效果,主要用到了jQuery的ajax()方 ...
- HTTP与AJAX深入揭秘,不使用AJAX实现页面无刷新
AJAX的原理是什么? 实际上就是发起HTTP请求,既然就是发起HTTP请求,那只要我们能够实现发起HTTP请求就可以在不使用AJAX的情况下实现相同的效果. 在前端有好多方式可以发起HTTP请求,比 ...
- JQuery 实现页面无刷新
对于JQuery实现页面无刷新的效果,即:应用这个JQuery这个组件,可以实现在页面上加载数据库中的数据信息,但是并没有给用户页面刷新的感觉,这样既可以有效的进行数据交互,也可以不妨碍用户的其他操作 ...
- Asp.net页面无刷新请求实现
Asp.net页面无刷新请求实现 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=&qu ...
- 浅谈页面无刷新技术ajax
现在一般网站都是用ajax来实现页面无刷新操作的. 什么是无刷新:ajax可以实现页面与后台的数据交互,用户完全感觉不出页面有任何的刷新,这就是AJAX的无刷新. ajax方法实现: 可以对ajax进 ...
- JavaScript实现页面无刷新让时间走动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- axios页面无刷新提交from表单
页面部分大概意思一下 <form method="post" enctype="multipart/form-data"> ... </for ...
- jQuery Pjax – 页面无刷新加载,优化用户体验
pjax 是 HTML5 pushState 以及 Ajax 两项技术的简称,综合这两个技术可以实现在不刷新页面的情况下载入 HTML 到当前网页,带给你超快速的浏览器体验,而且有固定链接.标题以及后 ...
随机推荐
- ImportError: cannot import name '_imagingtk'
问题描述 使用tkinter画pillow生成的图片时,在tkinter中抛出此异常. 解决方案 pip install -I --no-cache-dir Pillow 更新pillow 重启解决一 ...
- C /C++ 语言练习册
/************************************** 整数对应 32 bit 二进制数串中数字1的个数 2016-10-24 liukun ***************** ...
- TCP进制转换
/// <summary> /// 将十六进制字符串转化为字节数组 /// </summary> /// <param name="src">& ...
- android studio 中移除module和恢复module
一.移除Android Studio中module 在Android Studio中想要删除某个module时,在Android Studio中选中module,右键发现没有delete,如图: An ...
- mybatis判断传入list大小
<if test="tenantIds.size() > 0"> AND A.PROC_TARGET_ID IN <foreach collection=& ...
- caffe添加自己的层
首先修改src/caffe/proto/下的caffe.proto,修改好后需要编译 然后修改include/caffe/layers/logwxl_layer.hpp 然后修改src/caffe/l ...
- Oracle存储过程由例子到理论
1.基础环境 oracle HR环境添加新表 CREATE TABLE "HR"."cus_test" ( "id" BYTE) NOT N ...
- svn报错cleanup failed–previous operation has not finished; run cleanup if it was interrupted的解决办法
今天在svn提交的时候它卡顿了一下,我以为已经提交完了,就按了一下,结果就再也恢复不了,也继续不了了... 报错 cleanup failed–previous operation has not f ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- ReactNative 分享解决listView的一个郁闷BUG
用ListView的时候,会出现一个非常傻bi的情况,就是render的时候,listView不显示,需要碰/滑一下才会显示. 一开始我在怀疑自己是不是布局哪里有冲突,改到哭都没发现布局有什么问题,直 ...