2012-06-19 209 views
-1

這是我的代碼,我得到了一些錯誤,
錯誤:未捕獲的異常:[異常...「提示用戶中止」 nsresult:「0x80040111(NS_ERROR_NOT_AVAILABLE)」的位置:「JS框架::資源://gre/components/nsPrompter.js :: openTabPrompt ::行468" 的數據:無]未捕獲的異常

<%@ 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> 


請幫我找出原因,並重新編寫代碼。
在此先感謝。

+1

這是不是一個問題,確實有些其他的東西 –

+1

你錯過了之前'(「#output」)'$一個但這很難不縮進閱讀。 –

+0

使用螢火蟲調試,並找到究竟發生了什麼.. – vikrantx

回答

1

因爲這是一個POST,您需要return false for your form submit(例如,btnsubmit的客戶端處理程序)。另外,由於TextBox1TextBox2類型爲<asp:TextBox>,因此您需要捕獲它們的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. 
    }); 
});​