2011-02-07 65 views
0
function EmpCode(empCode) { 
    var queryString = ""; 
    var hasQuerystring = document.URL.indexOf('?'); 
    if (hasQuerystring != -1) { 
     queryString = document.URL.substring(hasQuerystring + 1, document.URL.length); 
     if (queryString == 'id=1') { 
      $.ajax({ 
       type: "POST", 
       url: "EmployeeBasicInfo.aspx/CheckEmpCode", 
       data: "{'empCode':" + empCode + "}",// Sending empCode which is a string 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function (msg) { 
        var errorMsg = (msg.d); 
        if (errorMsg != 'NA') { 
         alert(errorMsg); 
        } 
       } 
      }); 
     } 
    } 
} 

這裏是我的WebMethod發送一個字符串值將WebMethod

[WebMethod] 
public static string CheckEmpCode(string empCode) 
    { 
    string empCod = ""; 
    EmployeeFactory empFactory = new EmployeeFactory(); 
    empCod = empFactory.CheckCode(empCode); 
    return empCod; 
} 

當我送empCode爲「11479」 0R從阿賈克斯Web方法被調用任何整數。當我發送empcode作爲「C1026」或任何帶字符的字符串,然後webmethod沒有得到調用..

請建議我如何傳遞具有字符串值的empCode。

+0

請重新格式化您的問題。 – 2011-02-07 05:59:39

回答

0

圍繞EmpCode.Currently把雙引號您發送:

data: {'empCode': C1026} 

您需要發送:

data: {'empCode': 'C1026'} 
+0

非常感謝羅伯特。這對我很有幫助 – 2011-02-07 10:40:49

相關問題