这是我的页面:
<script type="text/javascript">
$(document).ready(function() {
$("#mainbutton").click(function() {
$.post("controller", {
action: "mainbutton",
name: "name"
},
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
<input id = "name" type="text" placeholder="Name" name="" /><span></span>
<input id="mainbutton" class="mainbutton" type="button" value="Rush my trial"/>
按下按钮时如何在请求中输入名称输入的值?
答案 0 :(得分:2)
使用var name=$('#name').val();
获取名称提交的值
<script type="text/javascript">
$(document).ready(function(){
$("#mainbutton").click(function(){
var name=$('#name').val();
$.post("controller",
{
action: "mainbutton",
name: name// pass parameter like this
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
答案 1 :(得分:0)
var name = $('#name').val();
$.post("controller",
{
action: "mainbutton",
type: "POST",
data: { 'name': name },
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});