title: Ionic 4 POST to PHP backend
body: <p>I'm trying to POST data to a PHP backend and receive back the values and push it into an array. Hence, I created a function to do just that. However, I'm not to change the API on the backend (written in PHP). So I cannot change it to suit my normal methods of using POST.</p>
  
  <p>This is my function </p>
  
  <pre><code>test() {
      let data = "method=getThis" + "&amp;db=myDatabase"
      this.http.post("API URL", data).subscribe(data =&gt; {
        this.result = data;   // get data in result variable
        this.items = JSON.stringify(this.result); // then convert data to json string
        // console.log(this.items);
        this.allData = JSON.parse(this.items); // parse json data and pass json string
        // console.log(this.allData.length); // got result of particular string
        this.array = [];
        for (var i = 0; i &lt; this.allData.length; i++) {
          this.array.push({
            data1: this.allData[i].data1,
            data2: this.allData[i].data2,
          })
        }
        console.log(this.array[0])
      })
    }
  </code></pre>
  
  <p>And this is an example function on the backend</p>
  
  <pre><code>else if($_POST['method']=="getThis"){
      global $conn;
      mysqli_select_db($conn, $_POST['db']);
      $name="";
      $result=array();
      $r=mysqli_query($conn,"select data1,data2 from table");
      while ($rs = mysqli_fetch_array($r,MYSQLI_ASSOC)){
          array_push($result,$rs);
      }
      echo json_encode(array("result"=&gt;$result));
  }
  </code></pre>
  
  <p>So how do I actually get it to post? I'm stuck here. I usually post with JSON and then decode the JSON on the backend. But this time around I'm not developing the backend and not changing it so gotta use the one provided. </p>
  
  <p>Posting using POSTMAN with this </p>
  
  <pre><code>method=getThis&amp;db=myDatabase
  </code></pre>
  
  <p>works well. Not sending JSON just a text. So how do I actually achieve this in Ionic. </p>