Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49183

$http.post request returns data null

$
0
0

@Pajimola wrote:

The status is fine but then the data return is null.
What i want to do is that the localstorage value which i put into a variable "userid" will be used in my php code.
Here is my code.
controller.js

var _this = this;
var link = 'http://127.0.0.1/mobile/subject.php';
var userid = localStorage.getItem('loginDetails');
console.log(userid);

  $http.post(link, {userid}).then(function(res){
    console.log(res);
    _this.response = res.data;
  })

this is my php code
<?php
header("Access-Control-Allow-Origin: *");
require_once('connection.php');

$post_data = file_get_contents('php://input');
$request = json_decode($post_data);

$userid = $request->userid;

$subject_sql ="SELECT SubjectName FROM subjects WHERE userid = '" .$userid. "' ";

$result = $con->query($subject_sql);

$re=$result->fetch_assoc();
echo json_encode($re);

?>

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49183

Trending Articles



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