Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229599

Ionic native POST sending no data

$
0
0

Ok, got it., thank you! After switching over to angular http it still isn't working though... The server is getting the request but no header or data... Thank you again!

import {Injectable} from "@angular/core";
import {Http, Headers, Response} from "@angular/http";
import {User} from "./user";
import {Config} from "../config";
import {Observable} from "rxjs/Rx";
import 'rxjs/add/operator/map';

@Injectable()
export class UserService {

  constructor(private _http: Http) {}


  //Makes http request to valid username and password
  login(user: User) {
    //Creates header to tell server that it is getting json
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    let options = { headers: headers };
    //Sets address to request
    var address = Config.apiUrl + "login/";

    //Creates JSON object that contains the data
    let data = JSON.stringify({
      username: user.username,
      password: user.password
    });

    //Make request to server
    return this._http.post(address, data, options)
    .map(res => {
      return(res);
    })
    .catch(error => {
      return Observable.throw(error);
    })
  }

I'd also like to mention that I am calling this method like this:

    this._userService.login(this.user)
    .subscribe((res: any) => {
   //Do stuff if status code is 2XX
   },
   res => {
  //Do stuff if status code is 5XX
   }

Viewing all articles
Browse latest Browse all 229599

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>