2

I have two functions, one works the other gives me this 404 error:

/get[object%20Object] 404 (Not Found)

The function getNews gives me that error, I used a console.log to see values of both functions, and I get the same: this.newId = "1", so I call both method with an string using the id of the "New" but it only works the onVote method.

Why on getNews case I got an Object on the request, and on onVote I have the id?

This is the component.ts file:

export class NewDetailsComponent implements OnInit
{
    params = new URLSearchParams();
    options = new RequestOptions({ withCredentials: true });
    oneNew: New;
    newId: string;

constructor(public http: Http, private activatedRoute: ActivatedRoute)
{    }

ngOnInit()
{
    this.activatedRoute.params.subscribe(params =>
    {
        this.newId = params['id']
    });

    this.getNews(this.newId)
}

getNews(id: string)
{
    this.params.set('id', id)
    this.options.search = this.params

    this.http
        .get(ApiConfig.API_URL + 'news/get' + this.options)
        .toPromise()
        .then(response =>
        {
            this.oneNew = <New>response.json()
        })
}

onVote(id: string)
{
    this.params.set('id', id.toString())
    this.options.search = this.params

    this.http
        .get(ApiConfig.API_URL + 'news/Vote', this.options)
        .toPromise()
}
2
  • When do you do a console.log of the url, do you have the real url? Z. Bagley has the answer I think. When you see such errors, that means that you have an mix-object where you need a string. Commented Oct 1, 2017 at 19:48
  • You have .get(ApiConfig.API_URL + 'news/get' + this.options) and .get(ApiConfig.API_URL + 'news/Vote', this.options). There might be something wrong with + and ,. Commented Oct 1, 2017 at 19:48

1 Answer 1

3

Your get is using + not , to add options:

getNews(id: string)
{
    this.params.set('id', id)
    this.options.search = this.params

    this.http
        .get(ApiConfig.API_URL + 'news/get', this.options)
        .toPromise()
        .then(response =>
        {
            this.oneNew = <New>response.json()
        })
}

should fix the issue

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

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.