I've researched this issue all day and it seems to be a somewhat common problem, but I have not been able to find a solution.
I am using jquery's $.ajax()
function to make a service call that updates some values in the database. It runs fine on localhost, but on the actual server I get a 500 Internal Server Error in the console window.
My client-side code is as below:
var param = FunctionToMakeKeyValueString();
$.ajax({
type: "POST",
url: "../Helpers/Autocomplete.asmx/OrderStatements",
data: { param: param },
clientType: "application/json; charset=utf-8",
datatype: "json",
async: true,
success: function () { ShowSuccess();},
error: function () { ShowError(); }
});
And server-side code is:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public void OrderStatements(string param)
{
IncomeStatementService service = new IncomeStatementService();
string[] comps = param.Split(';');
foreach (string s in comps)
{
int id;
short order;
string[] pieces = s.Split(':');
if (int.TryParse(pieces[0], out id) && short.TryParse(pieces[1], out order))
{
IncomeStatement statement = service.FindBy(id);
statement.Order = order;
service.UpdateOrder(statement);
}
}
}
}
the actual asmx file is just
<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %>
I'm sure the url is correct (the .js file is in a sibling folder to Helpers, which contains the asmx), but is there something else that I need to set in IIS or the web.config file? Thanks!