基本上,ajax
在 aspx 中,每 1000 毫秒轮询一次从 .cs 返回的值WebMethod
在 .cs 中是static GetData()
。属性被声明为静态public static int Percent { get; set; }
。我想要做的是当单击 btn1 时,它将将该值分配给Percent
和ajax
从中获取值WebMethod static GetData()
.
下载器.aspx.cs
public static int PERCENT { get; set; }
[WebMethod]
public static string GetData()
{
return PERCENT ;
}
protected void btn1_Click(object sender, EventArgs e)
{
DownloadLibrary downloader = new DownloadLibrary();
downloader.DoWorkSynchronous();
bool isLibraryBusy = true;
while (isLibraryBusy)
{
PERCENT = library.returnValue();
isLibraryBusy = downloader.IsBusy();
}
}
Downloader.aspx(ajax 轮询)
$(document).ready(function() {
$("#progressbar").progressbar();
setTimeout(updateProgress, 100);
});
function updateProgress() {
$.ajax({
type: "POST",
url: "Downloader.aspx/GetData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(msg) {
// Replace the div's content with the page method's return.
$("#progressbar").progressbar("option", "value", msg.d);
}
});
}
我想将值分配给Percent
但不幸的是,我无法做到这一点,因为Percent
is static
。如果我不声明Percent
as static
, the GetData
() 函数无法验证什么Percent
是。为了ajax
轮询,GetData()
必须在static
。如何给a赋值static
中的变量non-static function
?