我想跟踪我的电子商务网站产品下载的完整/成功和失败。我使用asp.net处理程序,我称之为throuh jquery ajax.i编写了一个代码。但是没有弹出downoad对话框,我仍然不知道成功和失败statistics.i需要根据返回的json数据更新我的数据库(对于成功/ false表示失败),来自asp.net处理程序.Anyone帮帮我。我提到的链接是
答案 0 :(得分:0)
//Assuming Download() is a thread
Private void DownLoad()
{
try
{
for(int i=0;i<=n;i++)
{
//Your code
Session["CurrentStatus"] = "SUCCESS"; //you can set download percentage here
}
Session["CurrentStatus"] = "COMPLETE";
}catch()
{
Session["CurrentStatus"] = "FAIL";
}
}
From Your UI you will fire an asynchronous event using PageMethod i.e
function GetCurrentThreadStatus()
{
//You can use JQuery Ajax here
//PageMethod is just an alternative
PageMethods.GetThreadStatus(function(status){
// success
if(status=="COMPLETE")
{
//Update DB :: success
}
if(status=="FAIL")
{
//Update DB :: fail
}
});
}
Code Behind : C#
[WebMethod]
public static string GetThreadStatus()
{
return (string)Session["CurrentStatus"];
}