gpt4 book ai didi

php - jQuery 向 php 发送多个需求

转载 作者:行者123 更新时间:2023-11-29 22:11:52 25 4
gpt4 key购买 nike

我有一个 jquery 函数,它将数据发送到 php。我通过 jquery 获取文本元素的值。当我将数据发送到 php 时,该数据会成倍增加。在第一个请求中,jquery 发送普通数据,在第二个请求中发送双倍数据,在第三个请求中发送三倍数据...
我尝试了很多方法,但结果都是一样的。下面我添加了源代码。

<p id="admAddH">Enter an email address of a new administrator:</p>
<p><input type="text" id="addAdmIR" /></p>
<p><button id="addAdmBtn">Add</button></p>

<script>
$.get('create_page.php?a=adminsAdd2&id='+id+'&admin='+v1,{addAdmIR:$(this).val()},function(data){
$('#noRefreshAdmAD').empty();
$('#noRefreshAdmAD').html(data);
$('#addAdmIR').val('');
});
</script>

和 PHP:

$id = $_GET['id'];
$admin = $_GET['admin'];

mysql_query("INSERT INTO `pages_admin` (`admin`,`pId`,`nameType`,`privacy`,`admins`,`ownshp`,`delPg`) VALUES ('$admin','$id','1','1','0','0','0')");

$query3 = mysql_query("SELECT * FROM `pages` WHERE `id`='$id' AND (`email`='".$_SESSION['user']."')");
$query9 = mysql_query("SELECT * FROM `pages_admin` WHERE `pId`='$id'");
$adQua = mysql_num_rows($query9);

while($row=mysql_fetch_array($query3)) {
echo'
<div id="adQuaAdmD">The Business Page &ldquo;'.$row['name'].'&rdquo; has '.$adQua.'&nbsp;administrators.</div>
<div id="adAdmList">';

while($row = mysql_fetch_array($query9)) {
echo'
<div id="adAdmListItem">&bull;&nbsp;&nbsp;&nbsp;'.$row['admin'].'
<span id="adRemoveAdm">
<span delete-admin="'.$row['id'].'">[x]</span>
</span>
</div>
';
}
echo'</div>';

感谢帮助

最佳答案

需要注意的是,我不知道您从哪里获取 id,因此我将其省略了。尝试使用这样的东西:

index.php

<script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<!-- wrap with form tags -->
<form id="add_admin">
<p id="admAddH">Enter an email address of a new administrator:</p>
<p><input type="text" name="email" /></p>
<p><input type="submit" value="Add" /></p>
</form>
<div id="resp"></div>
<script>
$("#add_admin").submit(function() {
$.ajax({
url: 'create_page.php',
type: 'post',
data: { add: "admins", email: $("input[name='email']").val() },
success: function(response) {
$("#resp").html(response);
}
});
// Return false so the page doesn't reload
return false;
});
</script>

create_page.php

<?php
session_start();
// You should do some sort of input validating here
$id = (!empty($_POST['id']) && is_numeric($_POST['id']))? $_POST['id'] : mt_rand();
$admin = (filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))? $_POST['email']:false;
// Don't do anything if the admin fails validation
if(!$admin)
return;
// On important note, you should not be using mysql_ anymore. Use
// PDO or mysqli_ with prepared/bound statements/values
mysql_query("INSERT INTO `pages_admin` (`admin`,`pId`,`nameType`,`privacy`,`admins`,`ownshp`,`delPg`) VALUES ('$admin','$id','1','1','0','0','0')");

$query3 = mysql_query("SELECT * FROM `pages` WHERE `id`='$id' AND (`email`='".$_SESSION['user']."')");
$query9 = mysql_query("SELECT * FROM `pages_admin` WHERE `pId`='$id'");
$adQua = mysql_num_rows($query9);

$i = 1;
while($row = mysql_fetch_array($query3)) { ?>
<!-- You should have unique id names, so adding a number
is probably the easiest way to do that -->
<div id="adQuaAdmD<?php echo $i; ?>">The Business Page &ldquo;<?php echo $row['name'].'&rdquo; has '.$adQua; ?>&nbsp;administrators.</div>
<div id="adAdmList<?php echo $i; ?>">
<?php
$a = 0;
while($row = mysql_fetch_array($query9)) { ?>
<div id="adAdmListItem<?php echo $a; ?>">&bull;&nbsp;&nbsp;&nbsp;<?php echo $row['admin']; ?>
<span id="adRemoveAdm<?php echo $a; ?>">
<span delete-admin="<?php echo $row['id']; ?>">[x]</span>
</span>
</div>
<?php
$a++;
} ?>
</div>
<?php $i++;
} ?>

关于php - jQuery 向 php 发送多个需求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31552129/

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