I have a problem with this.
below are my jquery code and aspx.cs code.
I should send $('#UserID').val() to WebMethod as a parameter.
but in WebMethod it is always null.
if I change $('#UserID').val() to any string, it works well.
#UserID is correct. because I made a alert window with this value.
and.. I already changed data: '{userId: "' + $('#UserID').val() + '"}',
to data: JSON.stringify({ userId: $('#UserID').val() }).
but nothing works.
$.ajax({
url: "register.aspx/IsIdAvailable",
type: "post",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: '{userId: "' + $('#UserID').val() + '"}',
dataFilter: function (data) {
var msg = JSON.parse(data);
if (msg.hasOwnProperty('d'))
return msg.d;
else
return msg;
}
})
[WebMethod]
public static bool test(string userId)
{
System.Diagnostics.Trace.WriteLine("userId: " + userId +"!");
...
}
output is always userId: !
$('#UserID').val()is null. Can you try this:alert($('#UserID').val());?register.aspx/IsIdAvailablein the script buttestin C#. Is it a mistake in copy paste here?