Ajax请求返回200但触发了错误事件

时间:2017-03-24 18:40:59

标签: c# jquery ajax asp.net-web-api

有一个类似的问题,但我仍然无法解决这个问题。

这是我的控制器方法:

@SpringBootApplication

始终触发错误

    [HttpPost]
    [ActionName("SaveProduct")]
    public IHttpActionResult SaveProduct(Product product)
    {
        bool saved = db.Instance.SaveProduct(product);
        if (saved)
        {
            IHttpActionResult response;
            HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
            string url = "http://localhost:8080/products/success.aspx";
           responseMessage.Content = new StringContent(url, System.Text.Encoding.UTF8, "application/json");
            response = ResponseMessage(responseMessage);
            return response;
        }
        return NotFound();
    }

1 个答案:

答案 0 :(得分:0)

我明白了。希望可以帮助别人

我替换了这个

        string url = "http://localhost:8080/products/success.aspx";
       responseMessage.Content = new StringContent(url, System.Text.Encoding.UTF8, "application/json");

对于此

        responseMessage.Headers.Location = new Uri(url);
        responseMessage.Content = new StringContent("{}");