hmm, if you serialized an object with the StudentId property, then I think it will be:
var studentId; function(json) { if (json.length > 0) studentId = json[0].StudentId; }
But if you just return StudentId , perhaps this:
var studentId; function(json) { if (json.length > 0) studentId = json[0]; }
Edit: Or maybe .length is not even required (I just returned the generic collections to JSON).
Edit # 2, it works, I just tested:
var studentId; jQuery.getJSON(url, data, function(json) { if (json) studentId = json; });
Change # 3, the actual JS is used here:
$.ajax({ type: "POST", url: pageName + "/GetStudentTest", contentType: "application/json; charset=utf-8", dataType: "json", data: "{id: '" + someId + "'}", success: function(json) { alert(json); } });
And in aspx.vb:
<System.Web.Services.WebMethod()> _ <System.Web.Script.Services.ScriptMethod()> _ Public Shared Function GetStudentTest(ByVal id As String) As Integer Return 42 End Function
travis Aug 27 '08 at 20:38 2008-08-27 20:38
source share