在js
文件中,我将 json 对象发送到 php 文件,但我不知道如何访问发送的对象。
下面代码中的第一行给了我:{"id":1,"email":"asd@qwe.co.uk","password":"xxxx","location":"London"}
js文件
app.showAlert(JSON.stringify(profile));
$.ajax({
type: "GET",
url:"http://www.domain.co.uk/test-login.php",
dataType: 'jsonp',
data: { data: JSON.stringify(profile) },
success:function(json){
// do stuff with json (in this case an array)
app.showAlert(JSON.stringify(json), "Login ok");
},
error:function(){
app.showAlert("Login faild", "Wrong username or password. Please try again.");
},
});
.php 文件:
<?php
header('Content-type: application/json');
$ret=$_GET['data'];
$ret=json_decode($ret, true);
echo '['.json_encode($ret[0]).']';
?>
PHP 是测试,因为我想检查用户是否传递了正确的详细信息,然后我将返回 json 对象'loggedin' => 1
左右,如果没有0
我也尝试通过 访问这个对象$ret=$_GET['profile'];
,但没有帮助。
我的问题是:如何传递 json 对象并在 php.ini 中访问它。