2010-08-11 128 views
0

我刚刚开始使用JQuery库,所以如果我缺少一些明显的东西,请耐心等待。我有一对夫妇的测试方法webserivce ...JQuery Ajax 500内部错误

[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; 
    } 

我可以用$就要求使用不带参数没有问题getDate方法,但我得到了500内部服务器错误当我尝试运行PerformPISearch方法(Web服务构造函数永远不会被击中)时从jQuery返回...因此,我假设我正在尝试将参数传递给该方法的方式出错,但我可以' W图什么?

 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); 
} 

回答

3

您是否尝试过删除 “()”:

data: {firstName: strFirstName, lastName: strLastName} 

或者把一切都变成字符串:

data: "{'firstName': '" +strFirstName + "', 'lastName': '" +strLastName+ "'}" 
+0

数据: “{ '的firstName': '” + strFirstName + “ ' 'lastName的':'” + strLastName + “'}” 我们赢家,谢谢... – AGoodDisplayName 2010-08-11 21:10:04

+0

你有没有试过$ .post?我用它来与asp.net的MVC,可以减少代码,如果它的工作原理:) $。员额(webserviceURL + “SystemServices.asmx/PerformPISearch”, { 姓:strFirstName, 名字:strLastName }, 功能(结果){ \t //做某事 }) – mathieu 2010-08-11 21:15:26

+0

不,我没有,但我会看看它。再次感谢。 – AGoodDisplayName 2010-08-12 16:17:45