Reputation: 2437
Using jQuery 1.11.0.
When I make the Ajax call, the error is
POST http://localhost:9909/Admin/ReportsService.asmx?GetQuestionSets 500 (Internal Server Error)
But I am able to browse the URL and run the method without any issue.
reports.js:
function getQuestionSets() {
$.ajax({
type: "POST",
url: "/Admin/ReportsService.asmx?GetQuestionSets",
data: "{ 'startDate': '" + $(".txtFromDate").val() + "', 'endDate': '" + $(".txtToDate").val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
console.log(msg.d);
},
Error: function (x, e) {
// On Error
}
});
}
ReportsService.asmx:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class ReportsService : WebService
{
[WebMethod]
public void GetQuestionSets(string startDate, string endDate)
{
//code to get data.
}
}
web.config:
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
</system.web>
The breakpoint for the method GetQuestionSets
is never hit.
What am i missing here.
Upvotes: 0
Views: 33
Reputation: 2534
Please check if the data posted to the endpoint is properly formatted. You mention: "I am able to browse the URL and run the method without any issue" -- is that with the actual data logged to the browser console, or by adding the dates by hand? See if the actual logged data (or what you're seeing if you make the call via Fiddler) causes an issue.
Upvotes: 0
Reputation: 21825
Problem seems to be in the url
you are calling your method as if you are passing a querystring.
Change:
url: "/Admin/ReportsService.asmx?GetQuestionSets"
to:
url: "/Admin/ReportsService.asmx/GetQuestionSets"
Upvotes: 1