I'm just starting to use the JQuery library so bear with me if I am missing something obvious. I have a webserivce with a couple of test methods...
[WebService(Namespace = "http://localhost/WebServices")]
[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 SystemServices : BaseWebService
{
[WebMethod(EnableSession = true)]
public string GetDate()
{
return DateTime.Today.ToShortDateString();
}
[WebMethod(EnableSession = true)]
public string PerformPISearch(string firstName, string lastName )
{
return firstName + lastName;
}
I can use the $.ajax request to use the GetDate method which does not have parameters with no issue, but I get the 500 Internal Server Error returned from jQuery when I try to run the PerformPISearch method (the web service constructor never gets hit)...So I am assuming I am doing something wrong with the way I am trying to pass the paramters to the method, but I can't figure out what...
function PerformSearch() {
var strFirstName = (txtFirstName.GetValue() == null ? "" : txtFirstName.GetValue());
var strLastName = (txtLastName.GetValue() == null ? "" : txtLastName.GetValue());
var webserviceURL = '<%= WebServiceURL %>'
$.ajax({
type: "POST",
url: webserviceURL + "SystemServices.asmx/PerformPISearch", //Can change to use GetDate and it works.
data: ({firstName: strFirstName, lastName: strLastName}), //thinking the problem is here
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
}
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}