javascript - Why does my website think the $http request is cross domain? -
in website i'm calling php page @ http://domain.com/angulartest/js/services/index.php
from service in same folder.
app.factory('vakmannen', ['$http', function($http) { return $http.get('http://www.domain.com/angulartest/js/services/index.php') .success(function(data) { return data; }) .error(function(err) { return err; }); }]); and php
<?php header("access-control-allow-origin: http://www.domain.com/angulartest/"); $servername = "localhost"; $username = "xxxxx"; $password = "xxxxx"; $dbname = "xxxxx"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "select * xxxx"; $result = $conn->query($sql); while($row = $result->fetch_array(mysql_assoc)) { $myarray[] = $row; } echo json_encode($myarray); ?> but every time $http.get runs firefox tells me cors header isn't right, i've tried on chrome no avail.
any appreciated!
if angular app in same folder, can use relative urls. can remove access-control-allow-origin header.
app.factory('vakmannen', ['$http', function($http) { return $http.get('/angulartest/js/services/index.php') .success(function(data) { return data; }) .error(function(err) { return err; }); }]);
Comments
Post a Comment