[英]Access Static Property Values From Code Behind Jquery/Javascript
我必須將最大值和百分比值讀入 jquery 函數。 我試過在頁面加載時將這些值讀入隱藏變量和會話變量中,它們總是返回 0。 這些是我的屬性:
public static int Max { get; set; }
public static int Percent { get; set; }
這是我的代碼隱藏:
[WebMethod]
public static string Test()
{
var y = 0;
var max = 100000;
Max = max;
for(int i = 0; i < max; i++)
{
y++;
Percent = y++;
}
if (y > max)
return "Success";
else
return "Fail";
}
這是我對按鈕單擊的 ajax 調用。 我正在嘗試使用另一個函數讀取每個 i 的最大值和百分比值。 我不確定如何將這些值調用到另一個函數中。
<asp:Button ID="btnGetData" runat="server" Text="Get Data" />
$(document).ready(function () {
$$('btnGetData').click(function () {
function readValues();
$.ajax({
type: 'POST',
url: 'Test.aspx/Test',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (Result) {
alert(Result.d);
},
error: function (Result) {
alert('Error!');
}
});
});
});
function readValues(){
var t = <%= Max%>;
var p = <%= Percent%>; //This has to be updated every few seconds until
//the for loop is finished.
}
我想你想要達到的目標類似於這個問題: Simple BackgroundWorker is not updated label on web page
基本上,您的選擇是:
對於 StackOverflow 上的直接答案來說,其中任何一個都可能有點過於復雜。 我建議嘗試圍繞這些建議整理一些東西,然后在遇到問題時再回來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.