テストのスコアをphpスクリプトに渡そうとしています。このスクリプトは、結果をユーザーにメールで送信します。スコアをコンソールに出力していますが、これはうまく機能しています(パーセンテージが表示されます)が、スコアの代わりに電子メールが送信されると、NaNと表示されます。
これが私のコードです...
score = roundReloaded(trueCount / questionLength * 100, 2);
$.ajax({
type: 'POST',
url: config.sendResultsURL,
data: { q:score },
complete: function () {console.log("Sending complete. The score was "+ score + "%");}
});
そして私のemailData.phpファイル...
$body = "You scored " . $_POST['q'] . "%";
$to = "someone@test.com";
$email = 'admin@test.com';
$subject = 'Results';
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
// Send the email:
$sendMail = mail($to, $subject, $body, $headers);
誰かが私を助けて、私が間違っていることを教えてもらえますか?
ありがとう