For this example, I will start with the web service. It's going to be asmx service that simply adds and subtracts numbers that it retrieves from the front end. Here's the code for the web service.
On the front end, I have couple of text fields, 1 option field to select to add or to subtract, a button that will trigger the script when clicked and a span element that will display the data. Here's the code for the html front end.
To start with I am calling jquery source file. Next, in the button click handler, I am forming the service url based on the selection. The important bit is this line
Note that a and b are parameter names in the service and I am sending the value of the text boxes. Finally, on success, I am populating the data in the span element. In case, error occurs, for example, if we type in "abc" in the text box or the web service is down, then the error function is fired and the text "Error!!!" is displayed within the span element.
Another thing to note is that the return value in json has .d at the end. This is within the success function as below.
The .d is a wrapper that ensures the payload is a json object.