【发布时间】:2010-11-30 14:40:16
【问题描述】:
我目前正在开发一个 ASP.NET Webforms 站点,但遇到了一个小问题。现在已经搜索了 2 个小时,我有一个截止日期,所以希望这里的人可以提供帮助。
在我的 .cs 文件中,我有以下 Web 方法
[WebMethod]
public static string IsJobEditable(int jobid)
{
try
{
string isEditable = "false";
JobsBLL jbl = new JobsBLL();
int jobStatusId = jbl.GetJobStatusId(jobid);
if(jobStatusId == Convert.ToInt32(ConstantsUtil.JobStatus.Waiting) || jobStatusId == Convert.ToInt32(ConstantsUtil.JobStatus.Edit))
{
isEditable = "true";
}
return isEditable;
}
catch (Exception ex)
{
throw ex;
}
}
在这种情况下,此函数将始终以字符串形式返回 TRUE。
在 Aspx 页面上我有以下内容
$(function () {
$.ajax({
type: "POST",
url: "Coordination.aspx/IsJobEditable",
data: "{jobid:" + jobid + "}",
contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (result) {
alert(result);
// This is written out in the alert {"d":"true"}
// I want this in a variable as a string
// so I can do a check on it before I do some other actions
// The format is not a String so i cannot split on it to
// retrieve the "true" part.
},
error: function (err, result) { alert(err); }
});
});
正如您在 cmets 中看到的,我在 Callback 方法中返回的值对我来说是一种奇怪的格式。类型未知,我需要此值才能继续执行围绕 Javascript 的一小部分的整个方法。
所以任何人都可以指出我可以将结果变量/数据作为 var 或其他任何可以让我将其放入 var(作为字符串)的方向。
【问题讨论】:
标签: c# jquery asp.net ajax callback