I am new to jQuery and Ajax and am having problems with the "message".
I am using the jQuery Ajax 'post' call to save data to the database. When I try to save the data, it passes null to my C # method. JQuery looks like this:
function saveInfo(id) {
var userID = id;
var userEmail = $('.userEmail').val();
var userName = $('.userName').val();
var dataJSON = {"userID": userID, "userEmail": userEmail, "userName": userName};
$.ajax({
type: 'POST',
url: '../../Services/AjaxServices.svc/SaveUser',
data:JSON.stringify(dataJSON),
contentType: 'application/json; charset=utf-8',
dataType: 'json'
});
return false;
}`
.userEmail and .userName are links to input field classes. C # code is as follows:
[ServiceContract(Namespace = "http://testUsePage.com")]
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class AjaxServices
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle=WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
public void SaveUser(User user)
{
}
}
I have a breakpoint inside the "SaveUser" method, and the passed User object is always zero. Thank!
EDIT: "POST" "GET" ajax, WebInvoke. ({ "UserID": UserID}) (public void SaveUser ( UserID)) . .