Web Api&返回jquery Ajax状态代码

时间:2016-09-20 15:38:09

标签: jquery asp.net-mvc asp.net-web-api

所以我试图返回并处理状态代码。 好吧我有一个Web应用程序,它执行Ajax调用(在服务器上调用本地方法)

喜欢这样

# this will call yourprog with ARGS given
# ...but -- beware! -- will cause bugs if there are more arguments than will fit on one
# ...command line invocation.
printf '%s\n' "$ARGS" | xargs yourprog

所以/预订/要求/  看起来像......

 $.ajax({
                url: "/Booking/Request/",
                type: 'POST',
                data: { model: JSON.stringify(model) },
                cache: false,
                crossDomain: true,
                async: false,
                dataType: 'json',
                statusCode: {
                    201: function(data) {
                        alert(data);
                    },
                    501: function(data) {
                        alert('Opps an error occured.');
                    }
                },
                error: function(event) {
                    alert('Error' + event);
                }
            });

然后调用远程api

[HttpPost]
public JsonResult Request(string model)
{
using (var booking = new HttpClient())
{
string addressRoute="https://api.remotelocation.com/Request";
booking.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = booking.PostAsync(addressRoute, new StringContent(model, Encoding.UTF8, "application/json")).Result;
return Json(response, JsonRequestBehavior.AllowGet);
}
}

然而返回以下错误(500),这不是201。 enter image description here

我做错了什么想法?

0 个答案:

没有答案