weixin_33724659 2014-08-20 21:01 采纳率: 0%
浏览 31

从Ajax调用Web API

I have the following code in .NET:

// GET api/EmailValidationStaging/5
public EmailValidation GetEmailValidation(long id)

This is a GET method, I am able to call it like this:

$("#buttonFIND").click(function (e) {
    e.preventDefault();
    $.get("[removed for privacy]/webservice/api/emailvalidationstaging/" + $("#textRecordId").val() + "?key=key", function (json) {
                $("#RecordId").val(json.RecordId);
                $("#Email").val(json.Email);
                $("#Validated").val(json.Validated);
                $("#IsEmailCurrent").val(json.IsEmailCurrent);
                $("#SentOut").val(json.SentOut);
                $("#TableRecordId").addClass("showStuff");
                //alert("success");
            })
                .fail(function () { });
        });

Everything works perfectly!

Now I need to do the same thing but this time it is a POST method and I have no idea how to do that. Everything I tried fails, please can someone give me a decent answer. I need to call this method:

This is a POST method, I am calling:

// POST api/EmailValidationStaging
public HttpResponseMessage PostEmailValidation(EmailValidation emailvalidation)

Additional information:

I am using Fiddler Web Debugger (Fiddler2)

Under compose I have Parsed (Selected POST) and then url like this: [removed for privacy]/webservice/api/emailvalidationstaging/?key=key

I am using HTTP/1.1 With the following parameters:

User-Agent: Fiddler
Host: 
Content-Length: 25
Content-Type: text/xml

RequestBody: {"MemberSSN":"999999999"}

The result I get is this:

HTTP/1.1 502 Fiddler - Gateway Connection Failed
Date: Thu, 21 Aug 2014 18:52:32 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Cache-Control: no-cache, must-revalidate
Timestamp: 11:52:32.933
  • 写回答

1条回答 默认 最新

  • weixin_33744141 2014-08-20 23:41
    关注

    Use jquery post method to call the api method:

    $.post()

    Here is a link for its documentation jquery post and make sure that your api action is marked as HttpPost

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!