hi,
There are some syntax errors with the JavaScript you posted. First, let look at the WebService, we need to include [System.Web.Script.Services.ScriptService] To allow this Web Service to be called from script. Let do a simple test
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
[WebMethod(Description = "Validate the login credentials")]
public bool Validate(string UserName, string Password)
{
if (Password == "test" && UserName == "test")
return true;
else
return false;
}
}
Then the JavaScript on your service.html page should look like
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
var Surl = "http://localhost:3031/HTMLService/Service.asmx/Validate";
$(document).ready(function () {
$("input#submit").click(function (event) {
var uid = document.getElementById("UserName").value;
var pwd = document.getElementById("Password").value;
var dataString = "{ 'UserName' : '" + uid + "', 'Password' : '" + pwd + "'}";
$.ajax({
ServiceCallID: 1,
url: Surl,
type: 'POST',
data: dataString,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
returnVal = result.d;
alert(returnVal);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
returnVal = '';
}
});
});
});
</script>