简体   繁体   中英

SyntaxError: Unexpected token < in JSON at position 0

SyntaxError: Unexpected token < in JSON at position 0

while retrieving json data using ionic 2 here is the link http://areeef.unaux.com/php/platforms.php

here is the code i am using to get json data

constructor( public navCtrl: NavController, private http: Http) {

this.http.get('http://areeef.unaux.com/php/platforms.php').map(res => res.json()).subscribe(data => {
   console.log(data);
}); }

when i run the same php code in local host then i can run the app without any error. but in online sever it is giving the error mentioned above so is that a problem of the server or error in my code?

Nothing seems wrong with the code. The problem is because your server not returning valid JSON.

Check the API's behaviour using postman plugin. I have checked it and it returning invalid JSON-

This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support

So, get your api working on postman first.

This error is normally caused by the server returning non JSON data. In this case, the PHP script could be returning an error message in form of HTML which will cause an error. The best approach for such errors is to debug the PHP script independently or accommodate the possibility of getting both html and JSON data on the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM