Wednesday, February 17, 2010

Consuming ASMX Web Services with jQuery

I was pleasantly surprised that this just worked...
<html>
<head>
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
$.ajax({
type: "POST",
url: "http://Server/Service.asmx/MethodName",
data: "{'firstName':'Gareth', 'lastName':'Hill'}",
contentType: "application/json; charset=iso-8859-1",
dataType: "json",
success: function(msg){
alert(msg.d);
}
});
</script>
</body>
</html>

Thanks to Dave Ward's post here.

No comments: