Web service returning 500 failed to load resource error

When I try to call C# Web service using jQurey, I am getting error "Failed to load resource: the server responded with a status of 500 (Internal Server Error)"

I'm trying to send a call using ajax but in Chrome it is raising an error here is my code


<script type="text/javascript">
$(document).ready(function() {
function SearchText() {

source: function (request, response) {
type: "POST",
contentType: "application/json; charset=utf-8",

url: "~/getitemdetails.asmx/GetItemNames",

data: "{'term':'" + document.getElementById('txtItem').value + "'}",

dataType: "json",
success: function (data) {
error: function (result) {
alert("No Match");

Web-Form HTML

<asp:TextBox ID="txtItem" CssClass="form-control col-md-3" runat="server"></asp:TextBox>

C# Web Method.

[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
public List<string> GetItemNames(string term)

System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

List<string> listCountryName = new List<string>();
string cs = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
SqlCommand cmd = new SqlCommand("spGetitemname", con);
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter parameter = new SqlParameter()
ParameterName = "@term",
Value = term
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())

return (listCountryName);




How can I solve this error?

Asked by:- RameshwarLate
: 5023 At:- 11/13/2018 11:41:09 AM
C# jQuery-ajax web-method-using-jquery

1 Answers
profileImage Answered by:- vikas_jk

500 errors mean the code on the server crashed or failed for some reason.

That could be because you sent parameters it didn't expect, sent them in a format it didn't expect, values out of range, or the code on the server is poorly written and doesn't check the input parameters before trying to process them, or some combination of the above.

Try these possible solutions

  1. Send paramater in Ajax as JSON.stringify(param) , like this
    var searchTerm= document.getElementById('txtItem').value; 
    var obj = { term :  searchTerm};
    var param = JSON.stringify(obj);  // stringify the parameter?
  2. try to make the WebMethod static
    public static List<string> GetItemNames(string term)
       //your code...

If none of the above works, check these links



above links explains how to call .asmx from jQuery Ajax.

At:- 11/13/2018 3:35:14 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly