Guest User

Untitled

a guest
Jun 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. export class QuizComponent implements OnInit {
  2.  
  3. constructor(private http: HttpClient) { }
  4.  
  5.  
  6. myData = { param1: 'This is param 1', param2: 'this is param 2' }
  7.  
  8.  
  9. sendmydata(){
  10.  
  11. const req = this.http.post('http://myhost.com/phpapi/api.php',this.myData)
  12. .subscribe(
  13. res => {
  14. console.log(res);
  15. // how can I access res.status here?
  16.  
  17. res.status;//this line says Property 'status' does not exist on type 'Object'
  18.  
  19. },
  20. err => {
  21. console.log("Error occured");
  22. }
  23. );
  24. }
  25.  
  26. <?php
  27.  
  28. header("Access-Control-Allow-Origin: *");
  29. header("Content-Type: application/json; charset=UTF-8");
  30. header("Access-Control-Allow-Methods: POST");
  31. header("Access-Control-Max-Age: 3600");
  32. header("Access-Control-Allow-Headers: Content-Type, Access-Control-
  33. Allow-Headers, Authorization, X-Requested-With");
  34.  
  35.  
  36. $db = "dbname";//Your database name
  37. $dbu = "dbuser";//Your database username
  38. $dbp = "dbpass";//Your database users' password
  39. $host = "localhost";//MySQL server - usually localhost
  40.  
  41.  
  42. $dblink = mysql_connect($host,$dbu,$dbp);
  43. $seldb = mysql_select_db($db);
  44.  
  45.  
  46. $postdata = file_get_contents("php://input");
  47. $request = json_decode($postdata);
  48.  
  49. $item1 = $request->param1;
  50. $item2 = $request->param;
  51.  
  52. $sql = mysql_query("INSERT INTO `$db`.`table` (`id`,`item1`,`item2`)
  53. VALUES ('','$item1','$item2');");
  54.  
  55. if($sql){
  56.  
  57. if (strcmp($item1, "") != 0) {
  58. echo '{"status":"ok"}';
  59. }
  60.  
  61. }else{
  62. echo '{"status":"error"}';
  63.  
  64. }
  65.  
  66. mysql_close($dblink);//Close off the MySQL connection to save resources.
  67. ?>
Add Comment
Please, Sign In to add comment