I have such problem: my app consists of index.html and bunch of other html files for different pages of my app which I navigate by ng-route. I want to post some data to server, but I can do it only if I put on index.html
Here is my angular code:
//post data to DB
app.controller('sign_up', function ($scope, $http) {
$scope.check_credentials = function () {
document.getElementById("message").textContent = "";
var request = $http({
method: "post",
url: window.location.href + "php/add_review.php",
headers: { 'Content-Type': 'application/json' },
data: {
review: $scope.review
}
});
request.success(function (data) {
document.getElementById("message").textContent = "You have login successfully with email "+data+request;
});
}
});
My PHP code:
<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$review = $request->review;
mysql_connect("localhost", "root", "");
mysql_select_db("reherse");
mysql_query("INSERT INTO reviews(review) VALUES('".$review."')");
//echo $request
echo $review;
?>
And my HTML:
<div id="login" ng-controller='sign_up'>
<input type="text" size="40" ng-model="review"><br>
<input type="password" size="40" ng-model="review"><br>
<button ng-click="check_credentials()">Login</button><br>
<span id="message"></span>
</div>
When I add this HTML on index.html it passes successfully and gives me a message with data which is passed to server. When this html code is added on other html file it returns me all html page(gives me message like You have login successfully with email here goes html code...).
Will be really thankful for help!