title: " Failed to load resource: the server responded with a status of 500 (Internal Server Error)"
body: <p>I really can't understand what is Exact problem here while calling the web service in the html page with JavaScript using ajax as it produces the error below:</p>
  
  <blockquote>
    <p>Failed to load resource: the server responded with a status of 500 (Internal Server Error)</p>
  </blockquote>
  
  <p>Ajax Code:</p>
  
  <pre class="lang-js prettyprint-override"><code>function Image() {
      $.ajax({
  
          type: "POST",
          url: "WebService.asmx/GetImage",
          data: "{'sDB': '" + "sDB" + "'}", 
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: OnGetMemberSuccess,
          failure: function (errMsg) {
              $('#errorMessage').text(errMsg);  //errorMessage is id of the  div
          }
      });
      function OnGetMemberSuccess(data, status) {
          alert("data" + data.d);
          $("#MemberDetails").html(data.d);
          $('input[type=button]').attr('disabled', false);
      }
  }
  </code></pre>
  
  <p>Where sDB is Null.</p>
  
  <p>Button click code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;input type="button" id="Button" value="Image" onclick="Image()" /&gt;
  </code></pre>
  
  <p>I have used the same code in my previous projects but its working fine. </p>
  
  <p>Web service code:</p>
  
  <pre><code>&lt;ScriptMethod(ResponseFormat:=ResponseFormat.Json)&gt; &lt;WebMethod()&gt; _
  Public Function GetImage()
  
      Dim cmd As SqlCommand = New SqlCommand
      Dim con = New SqlConnection("server = PROG19-PC;database = XIDBViews;Trusted_Connection = yes")
      cmd.Connection = con
      con.Open()
      Dim strQuery As String = ""
      Dim oSB As New StringBuilder
      Dim table As New Table()
      Dim tr As New TableRow()
      Dim td As New TableCell()
      Dim sFirstNameValue As String = String.Empty
      Dim sLastNameValue As String = String.Empty
      Dim DoBValue As String = String.Empty
      Dim sPhoto As String = String.Empty
  
      strQuery = "SELECT [sFirstName],[sLastName],[DoB],[sPhoto] FROM [XIDBViews].[dbo].[tblEmployee]  "
      cmd = New SqlCommand(strQuery, con)
      cmd.ExecuteNonQuery()
      Dim dr As SqlDataReader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
      oSB.Append("&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;" + " FirstName" + "&lt;/th&gt;&lt;th&gt;" + "Lastname" + "&lt;/th&gt;&lt;th&gt;" + "DoB" + "&lt;/th&gt;&lt;th&gt;" + "Party" + "&lt;/th&gt;&lt;th&gt;" + "Photo" + "&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;")
      While dr.Read()
          sFirstNameValue = dr("sFirstName").ToString
          sLastNameValue = dr("sLastName").ToString
          DoBValue = dr("DoB").ToString
          sPhoto = dr("sPhoto").ToString
  
          oSB.Append("&lt;tbody id=tbodyid'&gt;")
  
          oSB.Append("&lt;tr&gt;")
          oSB.Append("&lt;td class=border1&gt;")
          oSB.Append(sFirstNameValue)
          oSB.Append("&lt;/td&gt;")
  
          oSB.Append("&lt;td class=border1 &gt;")
          oSB.Append(sLastNameValue)
          oSB.Append("&lt;/td&gt;")
  
          oSB.Append("&lt;td  class=border1&gt;")
          oSB.Append(DoBValue)
          oSB.Append("&lt;/td&gt;")
  
          oSB.Append("&lt;td class=border1&gt;")
          oSB.Append(sPhoto)
          oSB.Append("&lt;/td&gt;")
  
          oSB.Append("&lt;/tr&gt;")
          oSB.Append("&lt;/tbody&gt;")
      End While
      dr.Close()
      con.Close()
      MsgBox(oSB.ToString)
      'Debug.Print(oSB.ToString)
      Return oSB.ToString()
  End Function
  End Class
  </code></pre>
  
  <p>But this web service code is working fine and according to my knowledge problem is with the ajax code, can anyone please help me with this.
  Cheers.</p>