无法加载资源:服务器响应状态为404(未找到)

时间:2017-01-28 13:21:26

标签: angularjs

当我尝试将我的数据库从Mvc-AngularJs更新为wcf-Rest时我得到的错误为Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:9706/EmployeeService.svc/UpdatexyzData/Update/,但当我尝试从Fidler点击时它的工作正常

Service.Js

this.xmlDataUpdate = function (sss) {

        var ss = $http({
            url: RestApi+"/UpdatexyzData/Update/",
            method: "PUT",
            data: $httpParamSerializerJQLike(sss),
            headers: {
                 'Accept': 'application/json',
          'Content-Type': 'application/x-www-form-urlencoded ;charset=utf-8'
            }
        })
        return ss;
    }

2 个答案:

答案 0 :(得分:2)

您可以通过在wcf服务上创建global.asax文件来启用cors,

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE");

        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }
}

答案 1 :(得分:0)

尝试使用

'Content-Type': 'application/json ;charset=utf-8'

并禁用预检请求

app.config(function ($httpProvider) {
  $httpProvider.defaults.headers.common = {};
  $httpProvider.defaults.headers.post = {};
  $httpProvider.defaults.headers.put = {};
  $httpProvider.defaults.headers.patch = {};
});