【问题标题】:Uncaught Exception in my jquery script我的 jquery 脚本中未捕获的异常
【发布时间】:2012-06-21 09:32:19
【问题描述】:

这是我的代码,我遇到了一些错误,
错误:未捕获的异常:[异常...“提示被用户中止”nsresult:“0x80040111(NS_ERROR_NOT_AVAILABLE)”位置:“JS 框架 :: resource://gre/components/nsPrompter.js :: openTabPrompt :: line 468" data: no]

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="loginform.aspx.cs" Inherits="loginform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Untitled Page</title>
  <script src="js/jquery-1.6.js" type="text/javascript"></script>
   <script type="text/javascript">   
   $(document).ready(function(){
     $("#btnsubmit").click(function(){      
        $.ajax({    
          type: "POST",            
           url: "loginform.aspx/getdataval",
           data:"{'uname':'"+$("#TextBox1").val()+"','passwod':'"+$("#TextBox2").val()+"'}",           
           contentType: "application/json;charset=utf-8",   
           dataType: "json",         
           success: function(msg) {
           alert("welcome");
           AjaxSucceeded(msg);
           },
              error: AjaxFailed
      })
   });
});
           function AjaxSucceeded(result) {
              alert(result.d);
              var Emp=result.d;
             $("#output").append('<p>'+Emp.Sname+ ' ' + Emp.Sno+'</p>');
           }
           function AjaxFailed(result) {
              alert(result.status + ' ' + result.statusText);
              alert("Failure");
           }  

   </script>


</head>
<body>
   <form id="form1" runat="server">
   <div>
       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       <br />
       <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
       <br />

       <asp:Button ID="btnsubmit" runat="server" Text="Button" />
       <div id="output">
       </div>
   </div>
   </form>
</body>
</html>


请帮我找出原因并重新编写代码。
提前致谢。

【问题讨论】:

  • 这不是问题,真的是其他问题
  • ('#output') 之前少了一个 $,但如果没有缩进,这很难阅读。
  • 使用 firebug 进行调试并找出到底发生了什么..
  • 你的领域真的叫“passwod”吗?
  • 您确定没有绑定到表单的提交事件的处理程序吗?

标签: javascript jquery asp.net asp.net-ajax


【解决方案1】:

因为这是POST,所以您需要return false for your form submit(例如btnsubmit 的客户端处理程序)。此外,由于TextBox1TextBox2 的类型为&lt;asp:TextBox&gt;,您需要捕获它们的ClientID 以在客户端脚本中正确引用它们。下面的代码应该可以工作。

function AjaxSucceeded(result) {
    alert(result.d);
    var Emp = result.d;
    $("#output").append('<p>' + Emp.Sname + ' ' + Emp.Sno + '</p>');
}

function AjaxFailed(result) {
    alert(result.status + ' ' + result.statusText);
    alert("Failure");
}

$(document).ready(function() {
    $("#btnsubmit").click(function(e) {
        $.ajax({
            "type": "POST",
            "url": "loginform.aspx/getdataval",
            "data": "{'uname':'" + $("#<%=TextBox1.ClientID %>").val() + "','passwod':'" + $("#<%=TextBox2.ClientID %>").val() + "'}",
            "contentType": "application/json;charset=utf-8",
            "dataType": "json",
            "success": function(msg) {
                alert("welcome");
                AjaxSucceeded(msg);
            },
            "error": AjaxFailed
        });
        //required because "type" is "POST"
        e.preventDefault();
        return false;
        //although it's a good idea anyway because we
        //don't want a postback.
    });
});​

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多