Internal server error in jquery /json webmethod-VBForums
Results 1 to 3 of 3

Thread: Internal server error in jquery /json webmethod

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    512

    Internal server error in jquery /json webmethod

    hi to all

    I have following code in webservice

    Code:
    [WebMethod]
            public string  Records(string loginid,string pass)
            {
    
                //if (loginid == "Admin")
                //{
                //    return "Exist";
                //}
    
                return "";
    
                //else
                //{
                //    return "Not Exist";
                //}
                //DataTable dt = new DataTable("MyDataTable");
                //dt.Columns.Add("column1", typeof(System.String));
                //dt.Columns.Add("column2", typeof(System.String));
    
                //DataRow dr = dt.NewRow();
                //dr["column1"] = "Your Data";
                //dr["column2"] = "Your Data";
                //dt.Rows.Add(dr);
    
                //dr = dt.NewRow();
                //dr["column1"] = "Your Data";
                //dr["column2"] = "Your Data";
                //dt.Rows.Add(dr);
    
                //return dt;
    
            }
    and.aspx page is like this
    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Params.aspx.cs" Inherits="JQueryAjax.Params" %>
    
    <!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">
    <style type="text/css">
    .loading {  background-image: url('ajax-loader.gif');  background-repeat: no-repeat; } 
    
       
    
    </style>
        <title></title>
        <script src="jquery.js" type="text/javascript"></script>
        <script type="text/javascript">
        function CallService() {     
        $("#lblResult").addClass("loading");  
        $.ajax({    
        type: "POST",
        url: "MyService.asmx/HelloWorld",
        data: "{}",  
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: Success, 
        error: Error     
        });     }   
          function Success(data, status) {      
           $("#lblResult").removeClass("loading"); 
           $("#lblResult").html(data.d);   
             }     
               function Error(request, status, error) 
               {        
                $("#lblResult").removeClass("loading");
                $("#lblResult").html(request.statusText); 
                }
                
         function CallService1() {
                
         $.ajax({   
         type: "POST",
         url: "MyService.asmx/Add",  
         data: "{ 'value1': " + $("#txtValue1").val() + ", 'value2': " + $("#txtValue2").val() + "}",
          contentType: "application/json; charset=utf-8",  
          dataType: "json",     
          success: OnSuccess,
          error: OnError   
          });     } 
          
          function OnSuccess(data, status) {   
          $("#lblResult").html(data.d); 
           } 
           function OnError(request, status, error) { 
           $("#lblResult").html(request.statusText);     
           } 
           
           
             function CallService2() {
                  $("#lblResult").addClass("loading");
         $.ajax({   
         type: "POST",
         url: "MyService.asmx/Records",  
         data: "{ 'value1': " + $("#txt_login").val() + ", 'value2': " + $("#txt_pass").val() + "}",
          contentType: "application/json; charset=utf-8",  
          dataType: "json",     
          success: OnSuccess,
          error: OnError   
          });     } 
          
          function OnSuccess(data, status) {   
           $("#lblResult").removeClass("loading"); 
           $("#lblResult").html(data.d); 
           } 
           function Error(request, status, error) 
               {        
                $("#lblResult").removeClass("loading");
                $("#lblResult").html(request.statusText); 
                }
           
           
        </script> 
        
        
    
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <table>
                    <tbody>
                        <tr>
                            <th>
                                Value 1: 
                            </th>
                            <td>
                                <asp:TextBox ID="txtValue1" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <th>
                                Value 2: 
                            </th>
                            <td>
                                <asp:TextBox ID="txtValue2" runat="server" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            
                <asp:Button ID="btnGo" Text="Hello World" OnClientClick="CallService(); return false;" runat="server" />
                <asp:Button ID="Button1" Text="Add" OnClientClick="CallService1(); return false;" runat="server" />
                 
                
                <asp:Label ID="lblResult" Text="&nbsp;" Width="100%" runat="server" />
                <asp:Label ID="lblRecords" Text="&nbsp;" Width="100%" runat="server" />
                
                
                
            </div>
            <table class="style1">
                <tr>
                    <td>
                        Login ID</td>
                    <td>
                        <asp:TextBox ID="txt_login" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Password</td>
                    <td>
                        <asp:TextBox ID="txt_pass" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                    <td>
                       <asp:Button ID="Button3" Text="Login check" OnClientClick="CallService2(); return false;" runat="server" />
                    </td>
                </tr>
            </table>
        </form>
    </body>
    </html>
    and when i click on Button3(after providing loginid and password ) it gives me an error "Internal Server Error"

    Please reply ..any urgent reply would be good enough

    Thanks
    There is no achievement without goals

  2. #2
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: Internal server error in jquery /json webmethod

    What does the Windows Log say?

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,529

    Re: Internal server error in jquery /json webmethod

    This should be in the ASP.NET Forum (mods?).

    Your method signature is
    Code:
    Records(string loginid,string pass)
    but you are trying to call it as
    Code:
    Records()
    Note the missing parameters that aren't being sent from your jQuery code.

    You are currently sending a single unnamed string as the data, and so jQuery has no idea what to do with it. When the request reaches ASP.NET, that also has no idea what to do with it as the request is for
    Code:
    Records("{}")
    and nothing matches that request, hence the Internal Server Error. You would have picked this up if you had run the project in debug mode from Visual Studio.

    If you check the relevant jQuery documentation for $.ajax(), you will see that the data parameter can be a string or an object. The string parameter would only apply if your string is already in query-string format. It isn't, so you will want to send an object as the data parameter value which will then get converted by jQuery into the appropriate query-string format. An object would be specified with braces (as you already had), but without the surrounding quotes that turn it into a string.

    The "Records" method is expecting two strings in the querystring, "loginid" and "pass", so you will need to specify them both in the data parameter.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.