当我将一个整数值从 .net webservice 传递给 jquery 时,它会作为布尔值返回。
我的网络服务:
<WebMethod()> _
Public Shared Function returnRowId(ByVal User As String, ByVal ProgramName As String, Lesson As String) As Boolean
Dim RowId As Integer
Try
Dim ds As New progressTableAdapters.Progress_LessonsTableAdapter
RowId = ds.InsertFirstEntry(Lesson, Now, User, "", ProgramName)
Catch ex As Exception
RowId = 0
End Try
Return RowId
End Function
这是返回rowid的sql代码”
INSERT INTO Progress_Lessons
( Lesson, Start_Time, User_Name, IPAddress, Programs)
VALUES (@lesson,@start,@user,@IP,@Programs);
SELECT SCOPE_IDENTITY()
这是我调用 web 服务并捕获 rowid 的 ajax 代码:
function returnRowId() {
var dataString = {
User: $('#lblUser').val(),
ProgramName: 'Conditional Statements',
Lesson: $('#lblLesson').val()
};
var options = {
type: "POST",
url: 'cs.aspx/returnRowId',
data: JSON.stringify(dataString),
contentType: 'application/json; charset=utf-8',
dataType: 'JSON',
success: function (msg) {
$('#rowId').val(msg.d);
},
error: function (request, status, error) {
alert(request.responseText);
alert(status.toString);
}
};
$.ajax(options);
}
当我调试时,webmethod 中的返回值是合法的行号。但是调试 jquery 代码中的值它显示 msg.d=true。无法弄清楚为什么将行值转换为布尔值。
任何建议表示赞赏。