gpt4 book ai didi

javascript - 都使用 ajax 提交数据并加载消息

转载 作者:行者123 更新时间:2023-11-28 01:37:08 24 4
gpt4 key购买 nike

Reply div :

<a href="#" class="show_hide" style="text-align:right;">Reply</a>
<div class="slidingDiv">

<div class="container">
<div id="myDiv">
<a href="#" class="show_hide1" style="float:right; text-decoration:none; font-size:14px; font-weight:bold; color:#000;">
X</a>

<form method="post" name="form" action="">
<table width="97%" border="0">
<tr height="100px">
<td>Message</td>
<td>:</td>
<td colspan="4"><textarea name="msg" cols="50" rows="6" required></textarea></td>
</tr>
<tr height="30px">
<td>Email</td>
<td>:</td>
<td><input name="email" type="email" required/></td>
<td>Mobile</td>
<td>:</td>
<td><input name="mob" type="text" required placeholder="+91" maxlength="10"/></td>
</tr>
<tr height="30px">
<td colspan="6" align="right">
<input type="submit" value="Post" name="submit" class="submit_button" onclick="loadXMLDoc()"/></td>

</tr>
<div class="clear"></div>
</table>

<div class="clear"></div>
</form>
</div>
</div>

Ajax content :

在 while 循环中显示隐藏 div 的脚本

<script type="text/javascript">
$(document).ready(function () {
var $slides = $(".slidingDiv").hide();
$(".show_hide").show().click(function () {
//if it is the reply link then find the next element
var $slider = $(this).next(".slidingDiv");
if (!$slider.length) {
//if the link inside the slider div is cliced then find the ancestor element
$slider = $(this).closest(".slidingDiv");
}
$slides.not($slider).stop(true, true).slideUp();
$slider.stop(true, true).slideToggle();
});
});
</script>

Ajax which ll send data to database

<script type="text/javascript">
$(function() {
$(".submit_button").click(function() {
var textcontent = $("#content").val();
var dataString = 'content='+ textcontent;
if(textcontent=='')
{
alert("Enter some text..");
$("#content").focus();
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('<span class="load">Loading..</span>');
$.ajax({
type: "POST",
url: "action.php",
data: dataString,
cache: true,
success: function(html){
$("#show").after(html);
document.getElementById('content').value='';
$("#flash").hide();
$("#content").focus();
}
});
}
return false;
});
});
</script>

<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax.txt",true);
xmlhttp.send();
}
</script>

reply.txt

消息已发送

现在的问题是,我有 while 循环进行回复..所以如果我在第三个回复链接中发帖,第一个回复链接将通过消息发送消息发布..第二个验证不起作用 drctly 回复.txt 消息是显示 n 第三个值未插入数据库

最佳答案

您的 HTML

<a href="#" class="show_hide" style="text-align:right;">Reply</a>
<div class="slidingDiv">

<div class="container">
<div id="myDiv">
<a href="#" class="show_hide1" style="float:right; text-decoration:none; font-size:14px; font-weight:bold; color:#000;">
X</a>

<form method="post" name="form" action="">
<table width="97%" border="0" id="myID"> // Added ID
<tr height="100px">
<td>Message</td>
<td>:</td>
<td colspan="4"><textarea name="msg" cols="50" rows="6" required></textarea></td>
</tr>
<tr height="30px">
<td>Email</td>
<td>:</td>
<td><input name="email" type="email" required/></td>
<td>Mobile</td>
<td>:</td>
<td><input name="mob" type="text" required placeholder="+91" maxlength="10"/></td>
</tr>
<tr height="30px">
<td colspan="6" align="right">
<input type="submit" value="Post" name="submit" class="submit_button" onclick="loadXMLDoc()"/></td>

</tr>
<div class="clear"></div>
</table>

<div class="clear"></div>
</form>
</div>
</div>

你的 AJAX

function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
$("#myId").css("display", "none"); // Add this
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax.txt",true);
xmlhttp.send();
}

已删除 $

<script type="text/javascript">
$(document).ready(function () {
var slides = $(".slidingDiv").hide();
$(".show_hide").show().click(function () {
//if it is the reply link then find the next element
var slider = $(this).next(".slidingDiv");
if (!slider.length) {
//if the link inside the slider div is cliced then find the ancestor element
slider = $(this).closest(".slidingDiv");
}
slides.not($slider).stop(true, true).slideUp();
slider.stop(true, true).slideToggle();
});
});
</script>

关于javascript - 都使用 ajax 提交数据并加载消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21403390/

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