I am taking first steps with angular here and breaking my head about two stuff. the first is i cant pass variable from the view to http.post call.
in this index.html ng-click
passes the correct values:
<tbody>
<tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
<td><a href="{{data.link}}" target="_blank">{{data.songName}}</td>
<td>{{data.artist}}</td>
<td><a ng-click="deleteSong(data.songName, data.artist, data.link)"><i class="glyphicon glyphicon-trash"></i></a></td>
</tr>
</tbody>
and in app.js the deleSong function looks like this:
$scope.deleteSong = function($songName, $artist, $link) {
// Posting data to php file
$http({
method : 'POST',
url : 'ajax/deleteSong.php',
data : $scope.data, //forms user object
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
if (data.errors) {
// Showing errors.
$scope.errorSong= data.errors.song;
$scope.errorArtist= data.errors.artist;
$scope.errorLink= data.errors.link;
} else {
$scope.message = data.message;
}
});
$scope.user = null
}
and finally , deleteSong.php looks like this:
<?php
include('../includes/config.php');
$errors = array();
$data = array();
// Getting posted data and decodeing json
$_POST = json_decode(file_get_contents('php://input'), true);
$song = $_POST['song'];
$query="DELETE FROM songs WHERE songName = '$song'";
$mysqli->set_charset('utf8mb4');
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
echo $query;
?>
When i click the delete song icon, the function get called but the response i get is this:
DELETE FROM songs WHERE songName = ''
any idea what am i missing and why is the query not getting the data i passed to deleteSong.php
?