Hello,

Not sure what I'm doing wrong but I can't seem to send an* http post 
request* *but I am able to use the get to retrieve the information*. I like 
to know what it is that I'm doing wrong in this instance?

Any help you can provide would be greatly appreciated.

My service.ts file

import { Injectable } from '@angular/core';
import { Headers, Http, Response, URLSearchParams, RequestOptions } from 
'@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

import { PersonType } from '../services/persontype';

@Injectable()
export class UserLoginService{
    private userUrl = 
'http://localhost/angular2/loginv2/app/inc/userLoginDB.php';
    userLoginInformation: PersonType[];

    constructor(private _http: Http){  }

    userAuthenticationMethod(uInfo: any): Observable<any[]>{
       let headers = new Headers({ 'Content-Type': 
'application/x-www-form-urlencoded' }); 
       let options = new RequestOptions({ headers: headers });
      
       let params: URLSearchParams = new URLSearchParams();
       params.set('userName', uInfo.userName);// test name

   *     // return this._http *
*        //     .get(this.userUrl, {search: params})*
*        //     .map((res: Response) => res.json())*
*        //     .catch(this.handleError);  *

*        return this._http *
*            .post(this.userUrl, {search: params}, options)*
*            .map((res: Response) => res.json())*
*            .catch(this.handleError);    *       
    }//END - userAuthenticationMethod

   private handleError(error: any) {
    console.error('An error occurred1', error); // for demo purposes only
    return Observable.throw(error.message || error);
  }
}//END class



The PHP file that access the database

<?php
header("Access-Control-Allow-Origin: *");
include('dbhandler.php');
$dbcon = Connection::getConnection(); 
//$newSearch = $_GET['userName']; 
$newSearch = $_POST['userName']; 

try { 
$STMT = $dbcon ->query("SELECT * from tbl_users WHERE userName = 
'$newSearch' ");
$userListOutput = $STMT->fetchAll(PDO::FETCH_ASSOC); 
} 
catch(PDOException $e){
echo 'DB error: ' . $e->getMessage(); 
}
 echo json_encode($userListOutput); 
?>




-- 
You received this message because you are subscribed to the Google Groups 
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to