我有下面的代码..访问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