将字符串值发送到 WebMethod
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]
public static string CheckEmpCode(string empCode)
{
string empCod = "";
EmployeeFactory empFactory = new EmployeeFactory();
empCod = empFactory.CheckCode(empCode);
return empCod;
}
当我将 empCode 作为“11479”0r 发送来自 Ajax 的任何整数时,Web 方法正在调用。当我将 empcode 作为“C1026”或任何带有字符的字符串发送时,则不会调用 webmethod。
请建议我如何传递具有字符串值的 empCode。
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);
}
}
});
}
}
}
Here is my WebMethod
[WebMethod]
public static string CheckEmpCode(string empCode)
{
string empCod = "";
EmployeeFactory empFactory = new EmployeeFactory();
empCod = empFactory.CheckCode(empCode);
return empCod;
}
When i send the empCode as '11479' 0r any integers from Ajax the web method is calling. when i send the empcode as "C1026" or any string with characters then the webmethod is not getting called..
Please suggest me how to pass empCode which is having string value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 EmpCode 周围加上引号。当前您正在发送:
您需要发送:
Put quotes around the EmpCode.Currently you are sending:
You need to send: