[英]PHP Notice: Trying to get property of non-object error
I'm using Factory in AngularJS, The Script is 我在AngularJS中使用Factory,脚本是
app.factory('GetCountryService', function ($http, $q) {
return {
getCountry: function(str) {
// the $http API is based on the deferred/promise APIs exposed by the $q service
// so it returns a promise for us by default
var url = "https://www.bbminfo.com/sample.php?token="+str;
return $http.get(url)
.then(function(response) {
if (typeof response.data.records === 'object') {
return response.data.records;
} else {
// invalid response
return $q.reject(response.data.records);
}
}, function(response) {
// something went wrong
return $q.reject(response.data.records);
});
}
};
});
My Output Response Screen Shot: 我的输出响应屏幕截图:
My PHP Script: 我的PHP脚本:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
session_start();
$ip = $_SERVER['REMOTE_ADDR'];
$dbname = "xyzData";
$link = mysql_connect("localhost", "Super", "Super") or die("Couldn't make connection.");
$db = mysql_select_db($dbname, $link) or die("Couldn't select database");
$uid = "";
$txt = 0;
$outp = "";
$data = file_get_contents("php://input");
$objData = json_decode($data);
if (isset($objData->token))
$uid = mysql_real_escape_string($objData[0]->token, $link);
else if(isset($_GET['uid']))
$uid = mysql_real_escape_string($_GET['uid']);
else
$txt += 1;
$outp ='{"records":[{"ID":"' . $objData->token . '"}]}';
echo($outp);
?>
I got error_log message is 我收到error_log消息是
[18-Mar-2016 21:40:40 America/Denver] PHP Notice: Trying to get property of non-object in /home/sample.php
[2016年3月18日21:40:40美国/丹佛] PHP注意:尝试获取/home/sample.php中非对象的属性
I tried both $objData->token
and $objData->token[0]
. 我尝试了
$objData->token
和$objData->token[0]
。 But I got the same error notice. 但是我得到了同样的错误通知。 Kindly assist me...
请帮助我...
I tried the Solution provided in the Post Notice: Trying to get property of non-object error , But it fails so, I raised 50 Bounty Points for this post. 我尝试了“发布通知”中提供的解决方案:尝试获取非对象错误的属性 ,但失败了,因此,我为此帖子提高了50个赏金积分。 I tried to update my requirement in that post Question https://stackoverflow.com/review/suggested-edits/11690848 , But the Edit was Rejected so I posted my requirement as a new Question.
我试图在那条问题https://stackoverflow.com/review/suggested-edits/11690848中更新我的要求,但是编辑被拒绝了,所以我将我的要求发布为新问题。 Kindly assist me...
请帮助我...
$objData doesn't seem to be an object. $ objData似乎不是一个对象。
try $objData['token']. 尝试$ objData ['token']。
Or echo the object $objData and try to figure out what is its structure. 或回显对象$ objData并尝试找出其结构。
The AngularJS is not sending any Object instead it passes the GET element. AngularJS没有发送任何对象,而是传递了GET元素。
Just access the Value by simply using $_GET['uid']
只需使用
$_GET['uid']
访问值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.