<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jquery-1.12.0.min.js"></script>
<script src="Lash.js"></script>
</head>
<body>
first name <input id="txtFirstname" type="text" /><br />
last name <input id="txtLastname" type="text" /><br />
E-mail <input id="txtEmail" type="text" /><br />
password <input id="txtPassword" type="password" /><br />
<input id="btnRegister" type="button" value="Register" /><br />
</body>
</html>
/// <reference path="jquery-1.12.0.min.js" />
$(document).ready(function () {
$("#btnRegister").click(function () {
Register();
});
function Register() {
var obj = { Firstname: $("#txtFirstname").val(), Lastname: $("#txtLastname").val(), Email: $("#txtEmail").val(), Password: $("#txtPassword").val() };
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:7910/WebService.asmx/Registering",
data:JSON.stringify(obj),
datatype: "json",
success: function (data) {
alert("Successfully register");
},
error: function (data) {
alert("error");
}
});
}
});
[WebMethod]
public string Registering(string user3gmail, string pass3, string name3, string nickname3, string birth)
{
return "{\"registerPachage\":{\"Id\":26}}";
}
I'm a beginner in Ajax Jquery and I'm doing exercise to improve my knowledge about it. My problem is when I click #btnRegister it's print error not Successfully message . I think there's a problem in the parameters I passed on the ajax but I don't know what is it.
JSON.stringify(obj), it should work by simply passingobjto data