如何获取对象的详细信息

时间:2016-08-01 21:31:02

标签: php json

使用以下代码:

$fh = fopen('log.txt', 'w') or die("Can't open file.");
// output the value as a variable by setting the 2nd parameter to true
$results = print_r($_REQUEST['lat'], true);
fwrite($fh, $results);
fclose($fh);

我正在尝试输出传入的对象及其引用。入站对象是

$_REQUEST['lat'];

但是当我终于打印出来时,我得到的只是:

[object Object]

我尝试了多种方法来获取对象的数据,但没有任何工作。我在这里缺少什么?

当我只使用$_REQUEST函数运行print_r时,我得到了这个:

Array
(
    [lat] => [object Object]
    [long] => [object Object]
)

1 个答案:

答案 0 :(得分:2)

字符串[object Object]javascript中对象的默认字符串表示形式。看起来你试图从javascript(ajax?)向你的php代码发送请求,而不是发送你发送对象的数据。

如果你有这样的事情:

$.ajax({
    url: "page.php", 
    data: {'lat' : $('#input_element') }
    success: function(result){
        ...
    }
});

你应该这样做:

$.ajax({
    url: "page.php", 
    data: {'lat' : $('#input_element').val() }
    success: function(result){
        ...
    }
});
相关问题