0

I have the following controller:

function RegisterFormCtrl($scope, $http) {
    $scope.master = {};
    $scope.response = {};

$scope.update = function(reguser) {
    reguser.contactInfo.name = "MAIN";
    reguser.contactInfo.phone = "333-333-3333";
    reguser.contactInfo.address = "333 Elm St Indiana PA 15701";
    reguser.contactInfo.email = "someemail@johnson.com";
    reguser.name = "Joe Johnson";
    reguser.username = "joe.johnson";
    reguser.password1 = "abcDEF123-";
    reguser.password2 = "abcDEF123-";

    $scope.master = angular.copy(reguser);

    $http.post('http://imac.local:8080/api/register', reguser)
        .then(
            function(response) {
                console.log("SUCCESS");
                console.log(response);

            },
            function(response) {
                console.log("FAIL");
                console.log(response);

            });

};

When I trigger the update method, the $http.post kicks off and works technically. Meaning it fires sends the right data to my server, the server (restify) returns a 201 and Angular registers it.

REQUEST HEADERS:

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101         Firefox/28.0
Referer:    http://imac.local:8000/app/?
Pragma: no-cache
Origin: http://imac.local:8000
Host:   imac.local:8080
Content-Type:   application/json;charset=utf-8
Content-Length: 222
Connection: keep-alive
Cache-Control:  no-cache
Accept-Language:    en-US,en;q=0.5
Accept-Encoding:    gzip, deflate
Accept: application/json, text/plain, */*

RESPONSE HEADERS:

Date:   Sun, 06 Apr 2014 19:21:16 GMT
Content-Type:   application/json
Content-Length: 333
Connection: keep-alive

RESULT:

Request URL:    http://imac.local:8080/api/register
Request Method:     POST
Status Code:    HTTP/1.1 201 Created

However, the failure method gets called, "FAIL" gets printed, and the response object is empty.
One thing to note, the server is running on a different port on the same machine: client: http://imac.local:8000 server: http://imac.local:8080

I bring it up, because chrome wouldn't even fire post I have to run it in firefox because of non origin failure despite the same domain locally.

I'm about 3 days old as far as Angular/Node/JS goes so any help would be appreciated.

Thanks in advance.

Steve Holt
  • 85
  • 9
  • Look up Same Origin Policy and Cross Origin Resource Sharing. – Musa Apr 06 '14 at 19:43
  • Thanks, I did originally when I was having problems with Chrome. What I read was that it was a bug in Chrome. The source and destination are on the same domain, so I don't *think* thats the problem. Do you? Also functionally it works. – Steve Holt Apr 06 '14 at 20:45
  • Yes origin takes into account the port... and protocol as well. – Musa Apr 06 '14 at 20:49
  • Musa, thanks for the info. I got it to work now. The confusing thing was that it actually sent and the data was processed. Some references for those that find this: FOR RESTIFY (http://stackoverflow.com/questions/14338683/how-can-i-support-cors-when-using-restify) FOR ANGULAR: (http://thibaultdenizet.com/tutorial/cors-with-angular-js-and-sinatra/). – Steve Holt Apr 06 '14 at 21:23
  • Musa, if you want to post the answer, i'll give you the credit. – Steve Holt Apr 06 '14 at 21:27

0 Answers0