1
在js
文件我发送json对象到php文件,但我不知道如何访问发送的对象。在ajax访问php访问json
第一行给我说:{"id":1,"email":"[email protected]","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对象左右,如果不0
我也试图通过$ret=$_GET['profile'];
访问这个对象,但它并没有帮助。
我的问题是:如何传递json对象并在php中访问它。
什么是输出给你? print_r的输出给你什么? –
在哪里我应该使用'print_r'?问题是我不能一步一步检查发生了什么,因为如果我没有收到json对象,我会收到msg'Login faild'。 – miszczu
这个基本的想法是打印出你所描述的内容,以便更好地了解正在发生的事情。 –