来自servlet的请求,但我没有得到angularjs的响应

时间:2014-05-03 03:58:14

标签: java javascript angularjs java-ee servlets

if(request.getParameter("btnadd")!=null) {

            int eId = Integer.parseInt(request.getParameter("eId")); 

            String datepicker = request.getParameter("datepicker");

            String name = request.getParameter("name");

            String cmp = request.getParameter("cmp");

            String insertRecord = dataBaseEngine.insertDepartment(eId, datepicker, name, cmp);   

            String  btnadd = String.valueOf(insertRecord);

            response.setContentType("application/json");

            out.print("{\"btnadd\" : \"" + btnadd + "\"}");

            out.flush();

            out.close();

            request.getRequestDispatcher("").forward(request, response);
            response.sendRedirect("");
        }

AngularJs代码

     $scope.btnadd = function() {
         $.ajax({
            url: 'Srvlet',
            type: "POST",
            data: {
                    eId: $scope.newcontact.eId,
                    datepicker: $scope.newcontact.datepicker,
                    name: $scope.newcontact.name, 
                    cmp: $scope.newcontact.cmp
                },
             success: function(data, textStatus, jqXHR) {
                 console.log(data);
                 $scope.$apply(function(){
                     $scope.newcontact.btnadd = data.btnadd;
                 });
             },
             error: function(jqXHR, textStatus, errorThrown) {
                 console.log('Error : ' + jqXHR.responseText);
             }
        });  

    };

0 个答案:

没有答案