Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS $http POST with port number

Is it possible to do an HTTP post request using port number in the url?

This is fine

$http.post('http://localhost/httpPost.json', data);

But this is not working

 $http.post('http://localhost:8081/httpPost.json', data);
like image 938
BKM Avatar asked Aug 21 '13 09:08

BKM


1 Answers

Yes, it is possible to use the port number in AngularJS request. So the problem is not here.

Could you be a little bit more precise on "not working" ?

Check your browser console (F12 in Chrome, also F12 if you have firebug installed on Firefox). An error message is probably displayed in this console.

I suspect that the Cross-Origin policy prevent you from fetching httpPost.json. It will happens if the call is not made from where you are trying to extract the data (for example if you opened the browser from file system or from another server than the one running on 8081)

like image 107
bdavidxyz Avatar answered Sep 29 '22 07:09

bdavidxyz