发布使用AJAX的一种形式 [英] Posting a form using AJAX
问题描述
做ü有一个如何把我的单选按钮的名称
的想法 myAjaxPostrequest.send(参数);
参数可以是这样的:
VAR answername =的document.getElementById('选项1')名称;
VAR参数= answername;
?这code是使用AJAX来发布形式
和我的PHP页面需要的单选按钮的名称,点击
我想这code和它的作品,因为我想除了在数据库中插入。它意味着参数是问题
我要插入是位于单选按钮的名称brakects之间的数字。
我能做到这一点,当我发帖的形式没有AJAX,但现在我不能发送单选按钮的名称
任何关于什么我可以送的参数功能线索 myAjaxPostrequest.send(参数);
<形式ID =问题1的方法=邮报>
< BR />
&其中;差异无显着天空的颜色是...
< / P>< IMG的边界=0SRC =图像/ wonder.pngWIDTH =94高度=134/>< BR />< BR />< BR />
<输入类型=无线电ID =选项1名称=回答[1]值=正确!的onclick =submitFormWithAjax();/>蓝
< BR />
<输入类型=无线电ID =选项1名称=回答[1]值=假的!的onclick =submitFormWithAjax();/>红
< BR />
<输入类型=无线电ID =选项1名称=回答[1]值=假的!的onclick =submitFormWithAjax();/>绿色
< BR />
<输入类型=无线电ID =选项1名称=回答[1]值=假的!的onclick =submitFormWithAjax();/>白色
< /形式GT;
通过以下你可以传递参数来调用Ajax方式:
VAR URL =get_data.php;
VAR PARAMS =LOREM =存有与放大器;名称= binny;
http.open(POST,网址,真实);
//发送正确的头信息以及请求
http.setRequestHeader(内容型,应用程序/ x-WWW的形式urlen codeD);
http.setRequestHeader(内容长度,params.length);
http.setRequestHeader(连接,关闭);
http.onreadystatechange =功能(){//调用一个状态改变时的功能。
如果(http.readyState == 4和&安培; http.status == 200){
警报(http.responseText);
}
}
http.send(PARAMS);
do u have an idea of how to send my radio button name for
myAjaxPostrequest.send(parameters);
can parameters be like this:
var answername=document.getElementById('option1').name;
var parameters=answername;
? this code is for using ajax to post a form
and my php page needs the name of the radiobutton clicked
I tried this code and it works as I want except for inserting in the database. It means parameters is the problem
what I want to insert is the number located between brakects of the radiobutton name.
I could do it when I post form without AJAX but now I can't send the name of the radiobutton
any clue about what I can send as parameter for function 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>
By following way you can pass parameter to ajax call:
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的一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!