我有下面的代碼..訪問JSON對象通過PHP
if (config.sendResultsURL !== null)
{
console.log("Send Results");
var collate =[];
for (r=0;r<userAnswers.length;r++)
{
collate.push('{"questionNumber'+parseInt(r+1)+ '"' + ': [{"UserAnswer":"'+userAnswers[r]+'", "actualAnswer":"'+answers[r]+'"}]}');
}
$.ajax({
type: 'POST',
url: config.sendResultsURL,
data: '[' + collate.join(",") + ']',
complete: function()
{
console.log("Results sent");
}
});
}
用Firebug我得到這個從控制檯。
[{"questionNumber1": [{"UserAnswer":"3", "actualAnswer":"2"}]},{"questionNumber2": [{"UserAnswer":"3", "actualAnswer":"2"}]},{"questionNumber3": [{"UserAnswer":"3", "actualAnswer":"2"}]},{"questionNumber4": [{"UserAnswer":"3", "actualAnswer":"1"}]},{"questionNumber5": [{"UserAnswer":"3", "actualAnswer":"1"}]}]
從這裏腳本將數據發送到emailData.php讀取...
$json = json_decode($_POST, TRUE);
$body = "$json";
$to = "[email protected]";
$email = 'Diesel John';
$subject = 'Results';
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// Send the email:
$sendMail = mail($to, $subject, $body, $headers);
現在我得到了電子郵件但它是空白。
我的問題是我如何將數據傳遞給emailData.php並從那裏訪問它?
這個鏈接將幫助您找出解決辦法:http://stackoverflow.com/questions/2237601/how-to-get-the-post-values-from-serializearray-in-php – 2012-02-07 12:30:17
我真的希望它做到了!我只是不明白!也許我一直在盯着這太久了! – dieseljohn 2012-02-07 15:44:53