- Back to Home »
- jQuery , Web Service »
Posted by : Jebastin
Saturday, 14 December 2013
How to call a WebMethod of a Web Service using jQuery Ajax JSON
The following jQuery is used to call a WebMethod of a Web Service using jQuery Ajax JSON.jQuery:
- $(document).ready(function () {
- var Name = $("#name").val();
- var Email = $("#email").val();
- var Message = $("#msg").val();
- $.ajax({
- type: "POST",
- data: "{'Name':'" + Name + "','Email':'" + Email + "','Message':'" + Message + "'}",
- url: "/WebServices/WS.asmx/Contact",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (response) {
- if (response.d == true) {
- alert("Thank you for contacting JJ Technology Solutions.");
- }
- else {
- alert("Error sending email. Please try again later.");
- }
- }
- });
- });