我有一个包含jquery变成进度条的div列表。在.ready上,我构建了所有这些进度条的列表,并为每个进度条调用一个WebService,该服务获取一个值,该值指示进度条应该有多满。为此,我需要将DIV的ID传递给Web服务。
因为div在listView中,所以我手动将id设置为id=“completionBar_ult;%eval(“milestoneid”)%>。
但是,当我将这个ID传递到我的Web服务中时,每次都会显示为“未定义”。当我查看源时,它看起来设置正确。
以下是调用我的Web服务的jquery:
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$(".MilestoneCompletion").progressbar({ value: 0 });
$.each($(".MilestoneCompletion"), function(index, barDiv) {
$.ajax({
type: "POST",
url: "ProjectTracking.aspx/GetText",
data: "{'id':'" + $(barDiv).id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success:
function(msg) {
$(barDiv).progressbar("value", msg.d);
}
});
});
});
</script>
以下是当前不做任何事情的Web服务存根:
[System.Web.Services.WebMethod]
public static int GetText(string id)
{
return 75; // returns completion percent
}
下面是我在ListView中设置DIV的ID的位置:
<ItemTemplate>
<li class="ui-widget-content" >
...
<!-- when this div loads, I want to call my webservice -->
<div id="completionbar_<%# Eval("MilestoneID") %>" class="MilestoneCompletion" style="height:30px;"></div>
...
</li></ItemTemplate>
我想也许脚本是在listview databind设置DIV ID之前执行的?
我可以解决这个问题,还是我的方法存在根本缺陷?