页面js代码:
<script src="js/jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
var timer;
function progressShow()
{
//$("#progressSpan").text("<%=progressInt %>%");
$.ajax({
//url: "自写progressBar.aspx/returnProgress",
//type: "text/plain",
//contentType: "application/text;charset=utf-8",
url: "ashx/returnProgress.ashx",
success: function(data){
alert(data);
$("#progressDiv").width(data);
$("#progressSpan").text(data);
},
error: function(error){
alert("error: "+error);
}
});
}
window.onload = function(){ timer = setInterval(progressShow,1500);}
</script>
body:
<div id="contentDiv" style="width:100px; background-color:Gray;"> <div id="progressDiv" style="width:1px; background-color:Red;"> <span id="progressSpan" style="color:Black;"></span> </div> </div>
aspx.cs:
namespace progressBar进度条 { public partial class 自写progressBar : System.Web.UI.Page { public static int progressInt; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Thread thread = new Thread(new ThreadStart(progressUp)); thread.Start(); } } public void progressUp() { for (int i = 1; i < 101; i++) { Thread.Sleep(2000); progressInt = i; } } [WebMethod] public static string returnProgress() { //HttpContext.Current.Response.Write(progressInt); //HttpContext.Current.Response.End(); return progressInt.ToString(); } } }
ashx:
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class returnProgress : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(自写progressBar.progressInt); } public bool IsReusable { get { return false; } } }
实际上progressInt一直在增加,可是为什么取出来的progressInt全是0?
暮色呼如
缥缈止盈
偶然的你
慕森王
相关分类