Asp.net 向WebMethod发送字符串值
这是我的WebMethodAsp.net 向WebMethod发送字符串值,asp.net,asmx,webmethod,Asp.net,Asmx,Webmethod,这是我的WebMethod function EmpCode(empCode) { var queryString = ""; var hasQuerystring = document.URL.indexOf('?'); if (hasQuerystring != -1) { queryString = document.URL.substring(hasQuerystring + 1, document.URL.length); if
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);
}
}
});
}
}
}
当我将EMP代码作为'11479'0r从Ajax发送任何整数时,web方法正在调用。当我将empcode作为C1026或任何带有字符的字符串发送时,则不会调用webmethod
请建议我如何传递具有字符串值的empCode。在empCode周围加引号。当前您正在发送:
[WebMethod]
public static string CheckEmpCode(string empCode)
{
string empCod = "";
EmployeeFactory empFactory = new EmployeeFactory();
empCod = empFactory.CheckCode(empCode);
return empCod;
}
您需要发送:
data: {'empCode': C1026}
请重新格式化你的问题。非常感谢罗伯特。这对我很有帮助罗伯特对我很有帮助
data: {'empCode': 'C1026'}