Asp.net jqueryajax500内部错误
我刚刚开始使用JQuery库,如果我遗漏了一些明显的东西,请耐心等待。我有一个带有一些测试方法的webserivceAsp.net jqueryajax500内部错误,asp.net,jquery,Asp.net,Jquery,我刚刚开始使用JQuery库,如果我遗漏了一些明显的东西,请耐心等待。我有一个带有一些测试方法的webserivce [WebService(Namespace = "http://localhost/WebServices")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJA
[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;
}
我可以使用$.ajax请求来使用GetDate方法,该方法没有参数,没有问题,但是当我尝试运行PerformPISearch方法时,我从jQuery返回了500个内部服务器错误(web服务构造函数从未被命中)…所以我假设我试图将参数传递给方法的方式有问题,但我不知道是什么
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);
}
函数性能搜索(){
var strFirstName=(txtFirstName.GetValue()==null?“:txtFirstName.GetValue());
var strLastName=(txtLastName.GetValue()==null?“:txtLastName.GetValue());
var webserviceURL=“”
$.ajax({
类型:“POST”,
url:webserviceURL+“SystemServices.asmx/PerformPISearch”//可以更改为使用GetDate,并且可以正常工作。
数据:({firstName:strFirstName,lastName:strLastName}),//认为问题就在这里
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(msg){
阿贾克斯(味精);
},
错误:ajax失败
});
}
函数AjaxSuccessed(结果){
警报(结果d);
}
函数ajax失败(结果){
警报(result.status+''+result.statusText);
}
您是否尝试删除“()”:
或者把所有的东西都放在一个字符串中:
data: "{'firstName': '" +strFirstName + "', 'lastName': '" +strLastName+ "'}"
您是否尝试过删除“()”: 或者把所有的东西都放在一个字符串中:
data: "{'firstName': '" +strFirstName + "', 'lastName': '" +strLastName+ "'}"
数据:“{'firstName':'”+strFirstName+“,'lastName':'“+strLastName+”}“我们赢了,谢谢……你试过$.post了吗?”?我在asp.net mvc中使用它,如果它工作的话,可能会减少代码:)$.post(webserviceURL+“SystemServices.asmx/PerformPISearch”,{firstName:strFirstName,lastName:strLastName},函数(result){//do something}不,我还没有,但我会看看它。再次感谢。数据:“{'firstName':'”+strFirstName+“,'lastName':'“+strLastName+”}”我们赢了,谢谢…你试过$.post了吗?我在asp.net mvc中使用它,如果它工作的话,可能会减少代码:)$.post(webserviceURL+“SystemServices.asmx/PerformPISearch”,{firstName:strFirstName,lastName:strLastName},函数(result){//do something}不,我还没有,但我会看看它。再次感谢。