Im using angular 6 & I have never used angular before. I need to send data to nodejs server. Im using the following code in angular function
import { Component, OnInit } from '@angular/core';
import { HttpClient,HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
fun_add(Id, cat) {
return this.http.post('/go', data,
httpOptions).subscribe(result => {
console.log(result);
}, error => console.log('There was an error: '));
}
In my nodejs,
app.post('/go', function (req, res) {
console.log("hi");
})
But I couldnt go to the server. Im getting the error msg 'there was an error'. can anyone please help me with this?
http.post('http://localhost:port/go'
otherwise it is no valid URL/go
isn't really that relative, it will try to get the root of whatever the folder is ...Not only that's not very clear, but that's also very randomXMLHttpRequest
object it calls runs in the JavaScript environment hosted by a webpage. Relative URLs are relative to the URL of that page.