I am fetching data from database and want to fill it in the dropdownlist. Following is my Javascript code .
<pre lang="c#">
$(document).ready(function () {
alert(location.pathname);
$.ajax({
type: "GET",
url:location.pathname+ "SearchFromHome.asmx/AllCities",
data: "{}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: OnSuccess,
error: onerror
});
});
Following is the code in web service.
<pre lang="c#">
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json]
public List<City> AllCities()
{
List<City> cityList = new List<City>();
using (cab_4_21Entities1 d = new cab_4_21Entities1())
{
cityList = d.Cities.ToList<City>();
}
return cityList;
}
when I run the project, it gives 500 internal server error. In inspect element, console tab, the error location is shown in jquery file - jquery-2.1.3.min.js.