AJAX XHR-Call创建无效参数异常
本文关键字:参数 异常 无效 创建 XHR-Call AJAX | 更新日期: 2023-09-27 17:51:04
所以我尝试从异步任务(这里没有显示,因为它不相关,我认为它的工作)到Jquery-xhr请求的进度条的值。服务器端方法是不相关的,因为它的工作,jquery-xhr-调用也工作(仅第一次)。
ASPX-Code:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (hfworking.Value == "true")
{
LabelProgress.Text = hflabel.Value;
ProgressBar1.Maximum = Convert.ToInt32(hfPBMax.Value);
ProgressBar1.Value = Convert.ToInt32(hfPBVAL.Value);
}
}
</script>
<html>
<head runat="server" id="head1">
<script src="JavaScript.js" type="text/javascript"></script>
<script src="jquery-1.11.0.min.js" type="text/javascript"></script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="pageScriptManager" EnableViewState="true"/>
<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>--%>
<%----%><%--OnClick="Button1_Click"--%>
<asp:Button runat="server" ID="btnDoTask" Text="Do Task" OnClientClick="StartJavaScriptProgress()" />
<br />
<asp:Label ID="LabelProgress" runat="server" EnableViewState="true"></asp:Label>
<br />
<eo:ProgressBar ID="ProgressBar1" runat="server" Width="250px" BackgroundImage="00060301"
BackgroundImageLeft="00060302" BackgroundImageRight="00060303" ControlSkinID="None"
IndicatorImage="00060304">
</eo:ProgressBar>
<asp:HiddenField ID="hflabel" runat="server"/>
<asp:HiddenField ID="hfPBMax" runat="server"/>
<asp:HiddenField ID="hfPBVAL" runat="server"/>
<asp:HiddenField ID="hfworking" runat="server" Value="false" />
我的Javascript代码在外部Javascript.js:
function StartJavaScriptProgress() {
try {
//setTimeout(WebService(), 1000);
document.getElementById("hflabel").value = "Currently Working ...";
var intervall = window.setInterval(WebService(intervall), 1000);
}
catch (Error) {
alert(Error.Description + " " + Error.InnerException + " " + Error.StackTrace);
}
};
function WebService(intervall) {
try {
if (document.readyState == 'complete') {
$.ajax(
{
type: "POST",
url: "AsyncTest.aspx/GetProcess",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d.Progressvalue == 'FINISHED') {
window.clearInterval(intervall);
}
else {
document.getElementById("hfPBMax").value = response.d.Progressmaximum;
document.getElementById("hfPBVal").value = response.d.Progressvalue;
document.getElementById("hfworking").value = "true";
alert("Worked! the maximum is " + response.d.Progressmaximum + " and the actual value is " + response.d.Progressvalue + "!!");
}
},
error: function (response) {
alert(response.status + " " + response.responseText);
}
})
}
}
catch (Error) {
alert(Error.Description);
}
};
它总是给我的错误:"无效参数"的捕获SetInterval…我不明白为什么?此外,我没有得到与此代码的页面生命周期,它使调用,进入异常,如果我有一个断点设置为"hfPBMax"它使它进入异常后?甚至没有提到它跳转到Page_Load的频率,而这对我来说没有意义,从我了解到的asp.net生命周期…如果有人能帮助我解决我的误解和失败,那就太好了。
试试这个
var intervall = window.setInterval(function(){WebService(intervall)}, 1000);
,否则你传递给setInterval的是WebService(intervall)执行的结果,它可能不是一个函数,因此它会抛出一个异常