[英]Why isn't my JavaScript function being called?
Here is what I have so far for my Index site: 到目前为止,这是我的索引网站的内容:
<% if (Model.Data != null)
{
if (Model.Data.Rows.Count > 0)
{
var divLoadGif = string.Empty;
var divRealData = string.Empty;
for(int n = 0; n < Model.Data.Rows; n++)
{
divLoadGif = "divLoadGif_" + n.ToString("0000");
divRealData = "divRealData_" + n.ToString("0000");
%>
<div id="<%:divLoadGif%>" style="width: 100%;">
Please wait ...
<img src="/loading.gif" alt="loading ..." />
</div>
<div id="<%:divRealData%>" style="visibility: hidden;">
<div id="column_1" style="width: 25%; float:left;">
This
</div>
<div id="column_2" style="width: 25%; float:left;">
is
</div>
<div id="column_3" style="width: 25%; float:left;">
a test
</div>
<div id="column_4" style="width: 25%; float:left;">
row.
</div>
</div>
<script type="text/javascript">
AsyncFunction(<%: divLoadGif %>, <%: divRealData %>, n);
</script>
<% }
}
}
%>
The controller fills my Model.Data
. 控制器填充我的
Model.Data
。 For example: 例如:
Model.Data.Row
should be equal to 3. This means the loop will make 3 "rounds". Model.Data.Row
应该等于3。这意味着循环将进行3次“回合”。 The idea is that in each "round" a loading gif should be displayed while the div
part (with the 4 columns) is invisible. 这个想法是,在每个“回合”中,当
div
部件(带有4列)不可见时,应该显示加载的gif。
Then the JavaScript function AsyncFuntionCall
should be called. 然后应调用JavaScript函数
AsyncFuntionCall
。 (This failed.) (失败)
This JavaScript function becomes two "div tag ids" and n
(variable of the for loop). 该JavaScript函数成为两个“ div标签ID”和
n
(for循环的变量)。 It will then use AJAX to call a controller method. 然后它将使用AJAX调用控制器方法。
The controller method gets also the div tags and n
. 控制器方法还获取div标签和
n
。
Finally, the controller method will be called 3 times. 最后,控制器方法将被调用3次。 The controller method will return a "result" for every call.
该控制器方法将为每个调用返回“结果”。 Every call will need a few seconds before it returns a result to the AJAX functionality.
每个调用都需要几秒钟的时间才能将结果返回给AJAX功能。
The success: function (result) { result = $.parseJSON(result); ...}
success: function (result) { result = $.parseJSON(result); ...}
success: function (result) { result = $.parseJSON(result); ...}
part of my AJAX call will then do the following: success: function (result) { result = $.parseJSON(result); ...}
然后,我的AJAX调用将执行以下操作:
Parse the result
. 解析
result
。
Switch the div
with id="<%:divLoadGif%>"
to hidden. 将
id="<%:divLoadGif%>"
的div
切换为隐藏。
Switch the div
with id="<%:divRealData%>"
to visible. 将
id="<%:divRealData%>"
的div
切换为可见。
Replace the 4 "values" with the parsed values from result
. 将4个“值”替换为
result
解析的值。
Easy? 简单? Not for me :-( because I have some problems:
不适合我:-(因为我有一些问题:
The loop works fine. 循环工作正常。 But the JavaScript function
AsyncFunction
isn't called at all! 但是
AsyncFunction
没有调用JavaScript函数AsyncFunction
! What's going wrong? 怎么了
I have absolutely no idea how I can change the "This" "is" "a test" "row"
values in the success: function (result) { result = $.parseJSON(result); ...}
我完全不知道如何成功更改
"This" "is" "a test" "row"
值success: function (result) { result = $.parseJSON(result); ...}
success: function (result) { result = $.parseJSON(result); ...}
part of my AJAX call. success: function (result) { result = $.parseJSON(result); ...}
是我的AJAX通话的一部分。
尝试AsyncFunction(<%: divLoadGif %>, <%: divRealData %>, <%: n %>);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.