1

I am using angular js and sails js in my project. I am getting problem with http get() while sending data with special characters from angular to sails.

I want to use http post() instead of http get(). Can anybody help ? My code looks like

var employee = $scope.employee;
$http({
        method: 'POST',
        url: '/employee/saveEmployee',
        headers: {'Content-Type': 'application/json'},

        data: {"empName":"employee .empName",
               "age":"employee .age",
                "designation":"employee .designation",
                "empType":"employee .empType"

                }

    }).success(function (data) {
        alert(data);
    });
5
  • please include part of current code having issues. http post is fairly simple for angular : $http.post('/someUrl', {msg:'hello word!'}) and does not require changes on sails side in general. Commented Apr 27, 2015 at 10:40
  • @arkoak above I have provided sample code snipet and it gives 500 (Internal Server Error) and I am finding undefined in sails side... Commented Apr 27, 2015 at 10:49
  • angular code seems ok, you can output some vars to console using console.log and try to find the exact problem statement, then share that part of the code as well alongwith the actual problem description you get in the console. Commented Apr 27, 2015 at 10:58
  • "I am finding undefined in sails side..." what do you mean ? Please provide some console output, error message or something. A 500 always leads in an error logged in the console. Commented Apr 27, 2015 at 21:40
  • Its worked .... Just removed the Double code " " from Json like this:: data: { empName:employee .empName, age:employee .age, designation:employee .designation, empType:employee .empType } Commented Apr 28, 2015 at 10:25

2 Answers 2

1

If you are using a sails generated API, just change your url to /employee/create

Sails automatically generates standard CRUD routes that you can use out of the box.

Sign up to request clarification or add additional context in comments.

Comments

0

Its worked ....I have put the json in improper format.
Just removed the Double code " " from Json like this::

data: {
               empName:employee .empName,
               age:employee .age,
                designation:employee .designation,
                empType:employee .empType

                }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.