I have a C# ASP.NET web service running (successfully) on this PC. I can test the LogonUser method via IIS and also call it from a test console application.
I have a second project, an HTML page that calls the web service using jQuery. This always fails and so quickly I don't think it's actually communicating with the service, making me think there's a syntax error in the JavaScript.
Have I got things configured correctly?
C# Web method:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class TimeRecordingService : System.Web.Services.WebService {
[WebMethod]
public string LogonUser(string _usercode, string _password) {
...
}
}
HTML source:
<body>
<form id="logon" action="">
<h1>
Time Recording Logon</h1>
<p>
<label>Usercode</label>
<input id="usercode" type="text" />
</p>
<p>
<label>Password</label>
<input id="password" type="password" />
</p>
<p>
<a type="submit" class="submit" id="LogonUser">Logon</a>
</p>
</form>
<!--Browsers block while requesting, loading, and executing JavaScript, defer this until as late as possible.-->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("a#LogonUser").click(function (e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: 'http://143.96.130.156/TimeRecording/TimeRecordingService.asmx/LogonUser',
data: '{"_userCode": "' + $("input#usercode").val() + ", '_password': " + $("input#password").val() + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: OnSuccess,
error: OnError
});
function OnSuccess(data, status) {
alert(status);
}
function OnError(request, status, error) {
alert(status);
}
});
});
</script>
This is always returning an error immediately when I click the Logon button.
Can you see or think why?
Thank you, Aaron.