Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WCF Rest Services with JavaScript/Jquery

WCF Rest Services with JavaScript/Jquery

Scheduled Pinned Locked Moved C#
csharpjavascriptasp-netwcfjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pravin_mun
    wrote on last edited by
    #1

    I am working with WCF and Rest services, where i defined a UriTempalte with some http request, i know how to call this Request and Response functionality in ASp.Net, can i cal same Request, and get Response in Javascript/Jquery. I googled alot, please any one help me regarding this... Thnks in Advance..

    V 1 Reply Last reply
    0
    • P pravin_mun

      I am working with WCF and Rest services, where i defined a UriTempalte with some http request, i know how to call this Request and Response functionality in ASp.Net, can i cal same Request, and get Response in Javascript/Jquery. I googled alot, please any one help me regarding this... Thnks in Advance..

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      It's been a while, but it should be something like this I think.

      //Read the information from the fields and pass it via Ajax to a webmethod.
      //JQuery will block the raising of the click event of the button.
      //1. Get all the parameters from the form.
      var val1 = document.getElementById('clientid1').value;
      var val2 = document.getElementById('clientid2').value;
      var val3 = document.getElementById('clientid3').selectedIndex;
      var val4 = document.getElementById('clientid4').options[index].innerHTML;
      var val5 = document.getElementById('clientid5').innerHTML;

      //2. put the parameters in a key/value pair like string
      var datapropt = "{'val1':'" + val1 + "'";
      datapropt += ", 'val2':'" + val2 + "'";
      datapropt += ", 'val3':'" + val3 + "'";
      datapropt += ", 'val4':'" + val4 + "'}";

      //create function that will call the server side WebMethod
      $.ajax({
      type: "POST",
      url: "StaticWebMethods.asmx/TheWebMethodName",
      data: datapropt,
      //cache: false,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (result) {
      //alert(result + "");
      location.reload(true);
      }
      });

      the function in the StaticWebMethods.asmxfile would look similar to this:

      [WebMethod]
      public static bool TheWebMethodName(int val1, string val2, string val3, string val4){
      //method body here
      }

      Hope this helps.

      V.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups