admin管理员组文章数量:1315294
I am using angular's $http.get function to call a PHP script file to retrieve data
var $promise = $http.get("../php-bin/example.php",obj).success(function(data) {
console.log(data);
});
The php is supposed to just get data from a mysql db to figure out a way to get data into my app
$user = json_decode(file_get_contents('php://input'));
$email = $user->email;
$pass = $user->pass;
$con = //a mysql_connection;
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$validateEmail = "SELECT `Email` FROM `newUsers` WHERE `Email` = '$email' ";
if ($result = mysqli_query($con,$validateEmail)) {
if ($result->num_rows == 1){
$date = '2014-08-13';
//$sql = "INSERT INTO newUsers (Email, CreationDate, UserRef, Type, id) VALUES ('$email','$date','$email','Host','$ssid')";
$sql = "SELECT `email` FROM `newUsers` WHERE `hashpass` = '$pass' ";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($result);
return $row;
//I never receive this data in the angular app.
}
}
mysqli_close($con);
?>
Could some one point me to the correct way to do this.
I am using angular's $http.get function to call a PHP script file to retrieve data
var $promise = $http.get("../php-bin/example.php",obj).success(function(data) {
console.log(data);
});
The php is supposed to just get data from a mysql db to figure out a way to get data into my app
$user = json_decode(file_get_contents('php://input'));
$email = $user->email;
$pass = $user->pass;
$con = //a mysql_connection;
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$validateEmail = "SELECT `Email` FROM `newUsers` WHERE `Email` = '$email' ";
if ($result = mysqli_query($con,$validateEmail)) {
if ($result->num_rows == 1){
$date = '2014-08-13';
//$sql = "INSERT INTO newUsers (Email, CreationDate, UserRef, Type, id) VALUES ('$email','$date','$email','Host','$ssid')";
$sql = "SELECT `email` FROM `newUsers` WHERE `hashpass` = '$pass' ";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_assoc($result);
return $row;
//I never receive this data in the angular app.
}
}
mysqli_close($con);
?>
Could some one point me to the correct way to do this.
Share Improve this question asked Aug 17, 2014 at 0:52 inoabrianinoabrian 3,8001 gold badge21 silver badges27 bronze badges3 Answers
Reset to default 4I see you have a return
statement instead of an echo
statement. A return
statement is not printed in the PHP output. A return
statement outside a function has only sense when you include the file:
$returned = include('the_file_you_showed_here.php');
//you will hold the row here
A return
statement kills the current script returning to an includer script (if any), but does not send any value to the output (that's the purpose of die
/exit
). You should:
- Change the
return
toecho
. - Remember to have a
header('Content-type: application/json')
sent if you intend to send json data, before any actualecho
instruction or non-php content. - Remember to encode the data:
return json_encode($row)
.
in your php make sure you echo your result the echoed results get passed into your variable
for example if you are passing in a varibale say from your scope
function($scope,$http){
$scope.obj= "your variable";
$reuslt = http.get('yourlocation/yourfile.php?val='+obj');
your php script
<?
$value = $_GET['val']
//not your variables have been passed in and you can use it to do your custom function wich ever way you like
and echo your result after wards
?>
hope this helps
You cannot call relative paths like that. The file has to exist at the public directory or lower. For instance, if all of your files are in /home/yourname/public, you'd need to call /php-bin/example.php
instead, where php-bin is inside of the public directory (/home/yourname/public/php-bin).
本文标签: javascriptAngular JS httpget does not receive data from PHP scriptStack Overflow
版权声明:本文标题:javascript - Angular JS $http.get does not receive data from PHP script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741921603a2405035.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论