Php 使用ajax加载内容
我不熟悉ajax 我有index.htmlPhp 使用ajax加载内容,php,jquery,Php,Jquery,我不熟悉ajax 我有index.html <script> $(document).ready(function(){ $("button").click(function(){ $.ajax({url:"n.php",success:function(result){ $("#div1").html(result); }}); }); }); </script> <div id="div1" style="margin-le
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url:"n.php",success:function(result){
$("#div1").html(result);
}});
});
});
</script>
<div id="div1" style="margin-left: 25;"></div>
<button>Add Author</button>
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$.ajax({url:“n.php”,success:function(result){
$(“#div1”).html(结果);
}});
});
});
添加作者
n.php
Name:<input type="text" name="txtname">
age:<input type="text" name="txtage">
名称:
年龄:
我只想在“添加作者”按钮单击时在index.html页面上添加姓名和年龄文本框,而不刷新页面。但上面的代码只加载姓名和年龄文本框一次。每次单击按钮时我都需要
编辑:
现在,如果我想放置另一个按钮“删除作者”,并想执行完全相反的操作(即删除两个文本框),我应该怎么做?你能帮忙吗 想知道如何检查验证服务器端 请帮助。更改此设置
$("#div1").html(result);
到
因此,每次单击按钮时,它都会附加文本框。更改此选项
$("#div1").html(result);
到
因此,每次单击按钮时,它都会附加文本框。请尝试以下操作:
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url:"n.php",success:function(result){
$("#div1").append(result);
}});
});
});
</script>
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$.ajax({url:“n.php”,success:function(result){
$(“#div1”)。追加(结果);
}});
});
});
使用append
而不是html
append
将在div中存在的任何内容的末尾添加响应,其中html
将替换当前内容。尝试以下操作:
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url:"n.php",success:function(result){
$("#div1").append(result);
}});
});
});
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url:"n.php",success:function(result){
$("#div1").append(result);
}});
});
});
</script>
<div id="div1" style="margin-left: 25;"></div>
<button>Add Author</button>
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$.ajax({url:“n.php”,success:function(result){
$(“#div1”)。追加(结果);
}});
});
});
使用append
而不是html
append
将在div中存在的任何内容的末尾添加响应,其中html
将替换当前内容。
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url:"n.php",success:function(result){
$("#div1").append(result);
}});
});
});
</script>
<div id="div1" style="margin-left: 25;"></div>
<button>Add Author</button>
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$.ajax({url:“n.php”,success:function(result){
$(“#div1”)。追加(结果);
}});
});
});
添加作者
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$.ajax({url:“n.php”,success:function(result){
$(“#div1”)。追加(结果);
}});
});
});
添加作者
现在,如果我想按下另一个按钮“删除作者”,并想执行完全相反的操作(即删除两个文本框)。我该怎么办?你能帮个忙吗?现在如果我想按下另一个按钮“删除作者”,并想执行完全相反的操作(即删除两个文本框)。我该怎么办?你能帮忙吗?