gpt4 book ai didi

ajax - 使用AJAX发布表单

转载 作者:行者123 更新时间:2023-12-05 00:52:11 25 4
gpt4 key购买 nike

您是否知道如何发送我的单选按钮名称

myAjaxPostrequest.send(parameters);


参数可以像这样:

var answername=document.getElementById('option1').name;

var parameters=answername;


?此代码用于使用ajax发布表单

和我的PHP页面需要单击单选按钮的名称

我尝试了这段代码,除了插入数据库外,它都可以按我的要求工作。这意味着参数是问题

我要插入的是位于单选按钮名称的制动器之间的数字。

当我发布不带AJAX的表单时可以这样做,但是现在我无法发送单选按钮的名称

关于我可以作为功能 myAjaxPostrequest.send(parameters);的参数发送的任何线索吗?

<form id="Question1" method="post"> 
<br />
<P> The sky color is..
</P><img border="0" src="images/wonder.png" width="94" height="134"/><br /><br /><br />
<input type="radio" id="option1" name="answer[1]" value="correct!" onclick="submitFormWithAjax();"/> blue
<br />
<input type="radio" id="option1" name="answer[1]" value="false!" onclick="submitFormWithAjax();"/> red
<br />
<input type="radio" id="option1" name="answer[1]" value="false!" onclick="submitFormWithAjax();"/> green
<br />
<input type="radio" id="option1" name="answer[1]" value="false!" onclick="submitFormWithAjax();"/> white
</form>

最佳答案

通过以下方式,您可以将参数传递给ajax调用:

var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);

关于ajax - 使用AJAX发布表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2999792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com