【发布时间】:2012-09-13 18:18:34
【问题描述】:
我正在使用 asp.net、JavaScript 和 HTML 处理程序。
在一个 asp 按钮 onclick 事件中,我像这样调用 JavaScript。
<asp:Button ID="btn_Tagging" CssClass="button" UseSubmitBehavior="false"
Text="Done" OnClientClick="DoneClick()" />
在脚本标记内的同一页面中,我编写了这样的 JavaScript:
<script type="text/javascript">
function DoneClick()
{
var checkLocation = "";
var txtMM = document.getElementById("hdn_Tagging").value;///Id s of textbox assigned in code behind MB--
txtMM = txtMM.slice(0, -1);
var arrTxtMM = txtMM.split(",");
for(var j=0;j<arrTxtMM.length;j++)
{
var Loc = document.getElementById(arrTxtMM[j]).value;
if(Loc == "")
{
checkLocation = "";
break;
}
else
{
checkLocation += Loc + ":";
}
}
if(checkLocation != "")
{
var url ='Handler/newExifDetails.ashx?Id='+txtMM+'&Location='+checkLocation+'';
var completetbl, html;
$.getJSON(url,function(json)
{
$.each(json,function(i,weed)
{
var res = weed.res;
alert(res);
if(res == null)
{
}
else
{
window.top.location.href = "Dashboard.aspx";
}
});
});
}
else
{
alert("Please pick the locations for all objects");
}
}
</script>
然后,当我单击按钮时,JavaScript 中的警报仅在我在 Firebug 或 Chrome 开发人员工具脚本中放置断点时才会显示,如果我放置断点它可以工作。如果不放置该断点,则警报既不会显示也不会重定向。
【问题讨论】:
-
这听起来像是那里某处的竞争条件。
-
重新检查你得到的 JSON 是否正确并且不包含语法错误,如果是这样,那么 $.getJSON 通常会静默失败。还要在重定向条目上放置断点并检查本地变量。可能正在发生一些奇怪的事情。
-
为什么在这里使用
asp:Button控件?你有这个按钮的点击事件的任何服务器逻辑吗?您的问题是回发发生在 $.getJson 函数将结果返回给客户端之前。 -
json 正在工作,就好像我在处理程序中放置了一个断点处理请求,但在 js 中没有任何断点...它转到处理程序,因此调用处理程序...然后将尝试在函数内发出警报检查...
-
按钮在 html 中看起来像这样......
标签: javascript asp.net