为了账号安全,请及时绑定邮箱和手机立即绑定

asp.net 用ajax到后台取值赋给html控件,可是取到的值一直没变?

asp.net 用ajax到后台取值赋给html控件,可是取到的值一直没变?

陪伴而非守候 2018-12-06 23:10:57
页面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?
查看完整描述

4 回答

?
暮色呼如

TA贡献1853条经验 获得超9个赞

url: "ashx/returnProgress.ashx"+new Date(),

试试

查看完整回答
反对 回复 2018-12-24
?
缥缈止盈

TA贡献2041条经验 获得超4个赞

你确认Page_Load方法被调用了吗?

查看完整回答
反对 回复 2018-12-24
?
偶然的你

TA贡献1841条经验 获得超3个赞

确定,我用timer定时取过 自写progressBar.progressInt的值,确实在自增啊

查看完整回答
反对 回复 2018-12-24
?
慕森王

TA贡献1777条经验 获得超3个赞

单步调试下看看

查看完整回答
反对 回复 2018-12-24
  • 4 回答
  • 0 关注
  • 644 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号