Note: to see the code for the .NET web service to be used with jQuery code below, see new post here:
How To Build a JSON Web Service to Send Mail in ASP.Net
Just to make sure we are all up to speed, a quick concept in extreme layman’s terms
- jQuery is a front-end thing, meaning it gets your browser to do stuff, like move stuff around and change stuff after it’s already been loaded from the server.
- Sending email is a back-end thing, meaning it requires talking to the server to send stuff.
Now that we are all up to speed, including my 5-month-old daughter, I think it’s clear that jQuery alone can’t do this, at least not without help. How does jQuery get help from the server? It uses an AJAX Post method to talk to a server, in our case, a web service, to send something and then get something back in return, like a result, which could be ignored by not specifying it in the AJAX Post call.
For this exercise, because I prefer .NET to PHP, I will be using a very simple .NET web service to send out the email, but this task can be accomplished by any server that accepts HTTP Post commands, like a CGI script.
Let’s review the steps that we will take to accomplish this task:
- Validate form data
- Send data to web service
- Interpret & display results from web service