php - Unexpected end of JSON input at JSON.parse

795

I made my RESTful mysql backend everything is good except that my feteched query has problem.I mean ,it show me nothing when my returned json is more than 2 objects. I'm working with ionic3 / http.

my select.php:

$sql = "SELECT * FROM products ORDER BY id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
     $data = array() ;
    while($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
    echo json_encode($data);
} else {
    echo "0";
}

my service file in ionic:

getProducts(){
    return this.http.get("http://localhost/api/products/select.php")
    .map(res=>{
      this.checkMe = res;

      if(this.checkMe._body !== "0"){
         return res.json()
      }

    } );
  }

I realy need your help. Thank you all.

141

Answer

Solution:

have you tried to do ..

getProducts(){
    return this.http.get("http://localhost/api/products/select.php")
    .map(res=>{
      this.checkMe = res.json() as any;

      if(this.checkMe._body !== "0"){
         return res.json()
      }

    } );
  }
935

Answer

Solution:

I had html tag into one of me fields in the MySQL that stops the json_encode() operation.


Thanks you all ??

People are also looking for solutions to the problem: php - How to prevent duplicating DB insertions when refreshing?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.