在這裏,我用簡單的HTML +的jQuery + AJAX文件 Ajax代碼是在這裏json_decode()無法正常工作
var email = "[email protected]";
var username = "ankur_07";
var password = "pass07";
var phone_no = "7676715797";
var datastring = {
"email": email,
"username": username,
"password": password,
"phone_no": phone_no
};
$.ajax({
type: "POST",
url: "../test/testreg.php",
data: {datastring : JSON.stringify(datastring)}, //with the page number as a parameter
dataType: 'html', //expect html to be returned
async: false,
success: function (data) {
alert(data);
/*if(data=="hello"){
message = "Mail Sent Successfully";
} else {
message = "Oops, mail doesn't send.!!!";
}
alert(message);*/
}
});
return false;
我從這個文件和螞蟻發送JSON在另一個testreg.php
文件 得到但它沒有解碼JSON其表現如下線使用echo
{\"email\":\"[email protected]\",\"username\":\"ankur_07\",\"password\":\"pass07\",\"phone_no\":\"7676715797\"}
if(isset($_POST['datastring']))
{
$data = $_POST['datastring'];
$data = json_decode($data);
print_r($data);
}
請幫我出這個卡死..
檢查json錯誤如果在json_decode之後使用了函數'json_last_error();'。 – Rikesh
可能[Magic Quotes](http://www.php.net/manual/en/security.magicquotes.php)?! – deceze
@Rikesh我們通過json_last_error()發現錯誤; – AndyBoy