繁体   English   中英

jQuery Ajax 500内部错误

[英]JQuery Ajax 500 Internal Error

我刚刚开始使用JQuery库,所以如果我遗漏了一些明显的东西,请多多包涵。 我有一个带有两种测试方法的网络服务...

[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 Internal Server Error(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);
 }

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

data: {firstName: strFirstName, lastName: strLastName}

或将所有内容放入字符串中:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM