For #1, you need to move the .val()
calls inside the method so they're fetched at the correct time, like this:
function SetStatus() {
var status1 = $("#statusBox").val();
var userID = $("#MainContent_userID").val();
$.ajax({
type: "POST",
url: "http://localhost/Sports/Services/UserWebService.asmx/SetStatus",
data: '{"status": "' + status1 + '", "userID": "' + userID + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
Though you should consider making this as an object and using .stringify
to handle any special characters.
For #2, asmx web services like to wrap the object, so it doesn't look like this:
{ "Status": "My Status", "UserID": 12, "StatusLikes": 0..... }
It actually looks like this:
{ "d": { "Status": "My Status", "UserID": 12, "StatusLikes": 0..... } }
So instead of this:
$("#MainContent_status").html(response.Status).fadeIn(1000);
You need this:
$("#MainContent_status").html(response.d.Status).fadeIn(1000);
Nick Craver
2010-08-21 02:00:07