我在通过以下函数提交一些隐藏的表单数据时遇到问题:
function displayCertificate()
{
window.open("../mailer.php","certificate","width=500,height=400,status=1")
}
var sHTML = "";
sHTML += '<FORM id="quizResults" method="POST" action="/articulate/mailer.php" enctype="text/plain" target="certificate" onSubmit="displayCertificate()">';
sHTML += '<INPUT TYPE="hidden" NAME="name" VALUE=\'' + g_arrResults[0].strStudentResponse + '\'>';
sHTML += '<INPUT TYPE="hidden" NAME="email" VALUE=\'' + g_arrResults[1].strStudentResponse + '\'>';
sHTML += '<br><input type="submit"><br>';
sHTML += '</FORM>';
alert(g_arrResults[0].strStudentResponse);
document.getElementById("divEmail").innerHTML = sHTML;
document.getElementById("quizResults").submit();
我需要的是打开一个新窗口,其中包含我通过 POST 发送给它的信息。窗口弹出正常,firebug 显示 POST 成功但数据似乎没有发送到我的新窗口。
这是我的 mailer.php:
<?php
print("name: ".htmlspecialchars($_POST['name']));
print("email: ".htmlspecialchars($_POST['email']));
?>
非常简单,但它正在输出:name: email:
谁能看出为什么会这样?我的解决方案必须是纯 JavaScript(因此请不要使用库)。
谢谢。
编辑以回应 alessioalex:
console.log(g_arrResults)
的输出是一个数组,如下所示:
[QuestionResult { nQuestionNum=1, strQuestion=" ", more...}, QuestionResult { nQuestionNum=2, strQuestion=" ", more...}, QuestionResult { nQuestionNum=3, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=4, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=5, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=6, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=7, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=8, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=9, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=10, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=11, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=12, strQuestion="A, B or C?", more...}]
这是数组中第一个对象的示例:
bFound
false
dtmFinished
Date {Thu Nov 17 2011 12:54:29 GMT+0000 (GMT Standard Time)}
nPoints
"0"
nQuestionNum
1
strCorrectResponse
" "
strInteractionId
"I4e28818f-4014-418c-a6e4-863679014098"
strLatency
"1862"
strObjectiveId
"I4e28818f-4014-418c-a6e4-863679014098"
strQuestion
" "
strResult
"neutral"
strStudentResponse
"Peter Rabbit"
strType
"fillin"
最佳答案
删除 window.open 代码并尝试将 target="_blank"添加到您的表单中:
<FORM target="_blank" id="quizResults" method="POST" ...>
关于php - Javascript:发布到新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8167160/