I am trying to receive json message from servlet based on angular js, but 
it always fails.

I am using the $http.post, but seems it does not work, could someone help 
me on that?

Here is my servlet code:

public class HelloWorld extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {

        response.setContentType("application/json");
        PrintWriter out = response.getWriter();

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("field_name", "hahaha");

        out.print(jsonObject);}

Here is my js:

var sandBoxApp = angular.module('sandboxApp', [])

sandBoxApp.controller('SandBoxCtrl', function ($scope, $http){

    $scope.heads = ['Field name', 'Original value', 'Processed value'];

    $scope.myData = {};
    $scope.myData.doClick = function(item, event) {

        var responsePromise = $http.post("HelloWorld");

        responsePromise.success(function(data, status, headers, config) {
            $scope.fromServer = data;
        });
        responsePromise.error(function(data, status, headers, config) {
            alert("AJAX failed!");
        });
    }});

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to