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:

  1. $(document).ready(function () {
  2. var Name = $("#name").val();
  3. var Email = $("#email").val();
  4. var Message = $("#msg").val();
  5. $.ajax({
  6.     type: "POST",
  7.     data: "{'Name':'" + Name + "','Email':'" + Email + "','Message':'" + Message + "'}",
  8.     url: "/WebServices/WS.asmx/Contact",
  9.     contentType: "application/json; charset=utf-8",
  10.     dataType: "json",
  11.     success: function (response) {
  12.         if (response.d == true) {
  13.             alert("Thank you for contacting JJ Technology Solutions.");
  14.         }
  15.         else {
  16.             alert("Error sending email. Please try again later.");
  17.         }
  18.     }
  19. });
  20. });

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Link To This Post/Page

Spread The Word

Add this button to your blog:
JJ Technology Solutions

Blog Archive

Trackers

eXTReMe Tracker
facebook

- Copyright © JJ Technology Solutions - Powered by Source Code Solutions -