I am trying to call a web service(.asmx) method present in same solutions itself(I am using Visual Studio 2012 Web Express) using Jquery Ajax Calls, I am getting failure error message as '500 Internal Server Error '. Please tell me what changes I need to make In web configue or in any other place.
<
script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js">$(document).ready(function () {
$("#btnUploadFile").click(function (e) { $.ajax({
type: 'POST',
url: "UploadEmployee.asmx/Test",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
}
,
error: function (response) {
alert(response.status + " " + response.statusText);
}
});
});
});
$("#btnUploadFile").click(function (e) { $.ajax({
type: 'POST',
url: "UploadEmployee.asmx/Test",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
}
,
error: function (response) {
alert(response.status + " " + response.statusText);
}
});
});
});
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
using System.IO; using System.Linq;
using System.Web; using System.Web.Script.Services;
using System.Web.Services;
namespace FinanceWebApplication.WebServices
{
/// /// Summary description for UploadEmployee
/// [WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)] // 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 UploadEmployee : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Test()
{
return "Hi";
}
} 
Santosh KumarPosted Jul 31, 2014, 6:03 AM
Thanks for Reply I found solution I have added resolve url javascript method
var pageUrl = '<%=ResolveUrl("~/WebServices/UploadEmployee.asmx")%>', which is hitting my service.
Then the final Script is
$(document).ready(function () {
$("#btnUploadFile").click(function (e) {
var pageUrl = '<%=ResolveUrl("~/WebServices/UploadEmployee.asmx")%>'
$.ajax({
type: 'POST',
url: pageUrl + "/Test",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
}
,
error: function (response) {
alert(response.status + " " + response.statusText);
}
});
});
});
Stephen KingPosted Jul 31, 2014, 6:02 AM
return new { returnValue = "returnData" };