-1

first Ill comment my config in server

i have a apache with my html page with angular in 80 port and other web server in port 4000 listening like a API

i am trying to make a $http request to my server but don't succes, just error message, this is my code

$http.post('http://localhost:4000/tareas', {msg:'asd'}).
success(function(data, status) {
    alert('funciono');
}).
error(function(data, status) {
    alert('error');

});

my server receive that request because i send a message when a controller is accesed, so the request connect with my API, but always execute the error my request in angular, even with $http.jsonp, that send me the error alert, my server return a simple json.

{data:'hurra.!', status:200}

i need a different response from my server to success?

even with F12 and neetwork, i see the request "canceled" with get and post, but my server send the message so i receive that request. with jsonp, chromium don't say a thin, everything is ok, but the $http.json still send me to error, is because my server response?

thanks to all.

xploshioOn
  • 4,035
  • 2
  • 28
  • 37

1 Answers1

0

well, searching more i find that cross domain request need "callback=JSON_CALLBACK" in the url and do a jsonp request, so changing my code to

$http.jsonp('http://localhost:4000/tareas?callback=JSON_CALLBACK'}).
success(function(data, status) {
    alert('funciono');
}).
error(function(data, status) {
    alert('error');

});

do the work and my ajax request now success... i find this in other tread, i put here the link for more info.

parsing JSONP $http.jsonp() response in angular.js

thanks

Community
  • 1
  • 1
xploshioOn
  • 4,035
  • 2
  • 28
  • 37