$http.post is not working in Ionic in Ionic/Cordova

9:43 PM

If you are facing some issue with '$http.post', actually problem with your server side code not JS code. If you are using PHP for server side then you've to use "file_get_contents('php://input')" for get your posted data. Full Code:

JS Code :

var data = {user : 'user',pass:'123456'}
$http.post('http://example.com/page_name',
    {data:JSON.stringify(data)}
)
.success(function(response){
 console.log('Success : '+JSON.stringify(response));
}).error(function(err){
 console.log('Error : '+JSON.stringify(err));
});

PHP Code :

$params = json_decode(file_get_contents('php://input'), true);

$data = json_decode($params['data'], true);
//here is your data which you post


You Might Also Like

0 comments