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. Web Development
  3. ASP.NET
  4. Problem with Post request in my ASP.NET Web API + jQuery

Problem with Post request in my ASP.NET Web API + jQuery

Scheduled Pinned Locked Moved ASP.NET
helpjsoncsharpjavascriptasp-net
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.
  • F Offline
    F Offline
    Farhad Eft
    wrote on last edited by
    #1

    Hi, I have an issue, that when I send get request to my ASP.NET Web API, also my post function in my controller gets called. Here is my code, I'd appreciate if anyone could help. I'd like to know what do I do wrong when I declare my post function that it also gets called with my get request. both my get and post function in my controller: public IHttpActionResult GetAffiliate(int id) { Classes.Data d = new Classes.Data(); Tuple result = d.getAffiliateById(id); Int16 status = result.Item1; Affiliate affiliate = result.Item2; if (status == 0) { return NotFound(); } return Ok(affiliate); } [AcceptVerbs("POST")] public HttpResponseMessage Post([FromBody]Address address) { Classes.Data d = new Classes.Data(); d.addressEdit(address); return Request.CreateResponse(HttpStatusCode.OK, "Address changed."); } my jQuery code where I apply get request: function getInfo() { //point to the api var uri = 'api/affiliate'; //clear the list div first $("#aff_name").empty(); var aff_id = $('#aff_id').val(); $.getJSON(uri + '/' + aff_id) .done(function (data) {... and here is my post request in jquery: $.ajax({ type: "POST", data: JSON.stringify(address), url: "api/affiliate/", contentType: "application/json" }); Thank you so much for your consideration.

    F 1 Reply Last reply
    0
    • F Farhad Eft

      Hi, I have an issue, that when I send get request to my ASP.NET Web API, also my post function in my controller gets called. Here is my code, I'd appreciate if anyone could help. I'd like to know what do I do wrong when I declare my post function that it also gets called with my get request. both my get and post function in my controller: public IHttpActionResult GetAffiliate(int id) { Classes.Data d = new Classes.Data(); Tuple result = d.getAffiliateById(id); Int16 status = result.Item1; Affiliate affiliate = result.Item2; if (status == 0) { return NotFound(); } return Ok(affiliate); } [AcceptVerbs("POST")] public HttpResponseMessage Post([FromBody]Address address) { Classes.Data d = new Classes.Data(); d.addressEdit(address); return Request.CreateResponse(HttpStatusCode.OK, "Address changed."); } my jQuery code where I apply get request: function getInfo() { //point to the api var uri = 'api/affiliate'; //clear the list div first $("#aff_name").empty(); var aff_id = $('#aff_id').val(); $.getJSON(uri + '/' + aff_id) .done(function (data) {... and here is my post request in jquery: $.ajax({ type: "POST", data: JSON.stringify(address), url: "api/affiliate/", contentType: "application/json" }); Thank you so much for your consideration.

      F Offline
      F Offline
      F ES Sitecore
      wrote on last edited by
      #2

      Are you sure you're simply not running both bits of javascript?

      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