undefined 405 (Method Not Allowed) Angularjs + aja

2019-08-14 08:54发布

问题:

i've been trying my hand on Angularjs + rest and when trying to get the data , i am getting the error - undefined 405 (Method Not Allowed)

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;

    }
}

i am able to see the json object when i directly access this url - http://abc.org/angularDemo/rest/demo/studentJson

回答1:

Change your web.config, removing the following keys:

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

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

Regards.