当用户单击按钮(以表格形式)时,将出现一个javascript提示框,询问用户名称,然后我要将javascript提示数据发送到php中,以便将其发送到phpmyadmin数据库。请注意,我已经尝试使用xmlhttprequest,但这没用,因为该网站位于https而不是http中
这是html表单:
<form method="post" id="user_form" action="Pages/Intro/Intro.php">
<input class="button" id ="start_button" type="button" name ="txt" onclick="loadUserName()" value="Go to Game(push Twice)">
<br>
<input class="button" id="help_button" name="help" type="button" onclick="location.href='Pages/Help/Help.html';" value="Help/F.A.Q" >
<br>
</form>
但是,我不确定如何发送此表单数据
JS(不发送至https):
function sendTextToServer(txt) {
var xhr = new XMLHttpRequest();
var formData = new FormData(myForm);
xhr.open("POST", "https://foo.php"); //Server goes after Post Method
//formData.append("txt", txt);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.addEventListener("readystatechange", function() {
if (xhr.readyState == 4 && xhr.status == 200) { // state DONE, status OK
// your request has been received, do what you want with the result here.
}
});
xhr.send(formData);
}
尝试使用ajax。请参阅下面的示例:
var formData = $('#myForm').serialize();
$.ajax({
url: 'https://foo.php',
type: 'POST',
data: formData,
success: function(data) {
// status code 200
// do something
},
error: function(data) {
// do something
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句