undefined 405(方法不允许)Angularjs + ajax

时间:2014-07-15 10:20:24

标签: ajax angularjs rest

我一直在尝试Angularjs +休息,当我试图获取数据时,我收到错误 - 未定义405(方法不允许)

main.js -

   url:'http://abc.org/angularDemo/rest/demo/studentJson',
                          type:'GET'}).success(function (sampleData) {
                              alert("here ... "+sampleData);
                        $scope.setPagingData(sampleData,page,pageSize);
                    }).error(function () {
                        alert("Error getting users.");
                    });


@Path("/demo")
@XmlRootElement
public class AngularDataObj {

    @GET
    @Path("/studentJson")
    @Produces(MediaType.APPLICATION_JSON)
    public List<StudentObj> studentJson(){

        List<StudentObj> list = new ArrayList<StudentObj>();
        StudentObj obj = new StudentObj();
        //Map<String,StudentObj> map = new HashMap<String,StudentObj>();
        for(int i=0 ; i< 50; i++){
            obj.setName("name"+i);
            obj.setAge(20+i);
            obj.setId(i);
            obj.setLocation("location"+i);
            list.add(obj);
            //map.put(""+i, obj);
        }

        return list;

    }
}

当我直接访问此网址时,我能够看到json对象 - http://abc.org/angularDemo/rest/demo/studentJson

1 个答案:

答案 0 :(得分:0)

更改您的web.config,删除以下键:

<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers>
        <remove name="WebDAV" />
    </handlers>
</system.webServer>

自: http://www.askamoeba.com/Answer/196/Http-405-Method-Not-Allowed-error-Web-API-Controller-PUT-Request-AngularJs

问候。