关于jQuery$.get()方法的几个问题
当我学习jquery时,我遇到了如下问题:关于jQuery$.get()方法的几个问题,jquery,Jquery,当我学习jquery时,我遇到了如下问题: <form id="form1" action="get1.php"> <p>评论:</p> <p>姓名:<input type="text" name="username" id="username"/></p> <p>内容:<textarea name="content" id="content" rows="2" cols="20"></text
<form id="form1" action="get1.php">
<p>评论:</p>
<p>姓名:<input type="text" name="username" id="username"/></p>
<p>内容:<textarea name="content" id="content" rows="2" cols="20"></textarea>
</p>
<p><input type="button" id="send" value="提交"/></p>
</form>
<div class="comment">已有评论</div>
<div id="resText"></div>
<script>
$(function () {
$("#send").click(function () {
$.get("get1.php",{
username:$("#username").val(),
content:$("#content").val()
},function(data,textStatus){
$("#resText").html(data);
})
})
})
</script>
我想知道为什么当我点击按钮时,它没有显示任何内容。非常感谢。您应该使用post功能向服务器发送数据,get请求应该仅用于获取一些数据。还要确保页面中包含了jQuery库
$("#send").click(function () {
$.post("get1.php",{
username:$("#username").val(),
content:$("#content").val()
},function(data,textStatus){
$("#resText").html(data);
})
})
您的控制台中是否出现任何错误。您还需要取消表单提交。对不起,我不知道您的意思。请您解释一下。表单发布可能会导致整个页面刷新。我会删除表单。删除表单后,当我单击按钮时,它也不会显示任何内容。我想知道如果删除表单,我应该使用哪个url