As in the previous workshop I played around some basic jQuery Ajax capabilities. This week i decided to explore the lowest level Ajax function.
<script type="text/javascript" language="javascript"
src="script/jQuery-1.3.2.min.js" "></script>
<script type="text/javascript">
var varType;
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
function CallService()
{
$.ajax({
type : varType, //GET or POST or PUT or DELETE verb
url : varUrl, // Location of the service
data : varData, //Data sent to server
contentType : varContentType, // content type sent to server
dataType : varDataType, //Expected data format from server
processdata : varProcessData, //True or False
success : function(msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
</script>
I created a basic WCF service to be consumed directly from the Web Page using the .ajax function above. This WCF service will return data in Jason format.
First we need to enable Ajax. We do that by setting the binding = “webHttpBinding” in the web.config file:
Secondly, configure the service to serialize Jason. We do that by decorating the method signature with the attribute ResponseFormat = jason in the service interface.
This is he WCF method (endpoint) implementation:
And finally, the jQuery Ajax call:
When the page loads, the alert shows the return data from the WCF service:





[...] using jQuery, we can consume an ASP .NET page method using jQuery and, as already explored in the workshop 6, we can consume WCF Services using jQuery. I could play around and show some of those variations [...]