jq不断请求ashx页的问题(c#)

ys123kj 2011-10-28 10:48:06
客户端界面中只放一个按钮,点击按钮跳转.ashx页面(服务器指定路径下的文件是否存在)

存在就下载到客户端 不存在返回客户端等待 每隔几秒在次请求.ashx页 依次请求。直至找个文件
...全文
94 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
o_Sara 2011-11-02
  • 打赏
  • 举报
回复

<script type="text/javascript">
function checkExecl()
{
var TIME;
$.ajax({
type:"GET",
async:false,
url:"ExeclHandler.ashx",
dataType:"text",
timeout: 1000,
success:handlerResponse
});

function handlerResponse(result)
{
if(result == "1")
{

clearInterval(TIME);//清楚调用

parent.location.href='文件地址';

}
else if(result == "0")
{
TIME = window.setInterval("checkExecl();",10000);//一分钟调用一次

}
}

}

</script>

<script src="../JS/jquery-1.4.1.js" type="text/javascript"></script>//引入
ys123kj 2011-11-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 somethingjack 的回复:]
你这就是一个下载功能吧 增加了一个每隔几秒请求.

Jqaury ajax .
我没有做几秒去请求的 自己修改下吧。

JScript code


using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web……
[/Quote]

虽然没帮到我。还是谢谢你。
SomethingJack 2011-10-28
  • 打赏
  • 举报
回复
你这就是一个下载功能吧 增加了一个每隔几秒请求.

Jqaury ajax .
我没有做几秒去请求的 自己修改下吧。

using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace Asiastar.NR.Ajax
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Handler1 : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";

string id = context.Request["id"].ToString();//获取资源的编号
System.IO.Stream iStream = null;
byte[] buffer = new Byte[10000];
int length;
long dataToRead;
NRBLL.File bf = new Asiastar.NRBLL.File();
Guid guid = new Guid(id);
if( bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"] != null )//判断数据库路径是否存在
{
string filepath = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"].ToString();//获取资源完整路径 D:\资源文件\600cc139-14cf-448e-9e50-daa972d35e01.jpg
string Oidfilename = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FileNam"].ToString();//旧文件名称
//string filename = System.IO.Path.GetFileName(filepath);//获取文件名称+后缀名 600cc139-14cf-448e-9e50-daa972d35e01.JPG
//int index = filepath.IndexOf(".");
//string filetype = filepath.Substring(index).ToLower();//后缀名
//string newfilename = Oidfilename;
//string filepath1 = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"].ToString().Substring(0,filepath.Length - 8);
try
{
string fileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(Oidfilename));//解码(注意这里2层解码)
Oidfilename = Oidfilename.Replace("+","%20"); //将“+”替换成“空格”
iStream = new System.IO.FileStream(filepath,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
dataToRead = iStream.Length;
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition","attachment; filename=" + HttpUtility.UrlEncode(Oidfilename,System.Text.Encoding.UTF8)); //下载的时候下载原来的文件名称
while( dataToRead > 0 )
{
if( context.Response.IsClientConnected )
{
length = iStream.Read(buffer,0,10000);
context.Response.OutputStream.Write(buffer,0,length);
context.Response.Flush();
buffer = new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
dataToRead = -1;
}
}

}
catch( Exception ex )
{
NR.Error.Log.LogType(ex.ToString());
}
finally
{
if( iStream != null )
{
iStream.Close();
}
}
}
else
{
NR.Error.Log.LogType("找不到文件!");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧