簡體   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