gpt4 book ai didi

PHP 脚本在页面加载时自动运行

转载 作者:行者123 更新时间:2023-11-30 22:24:19 24 4
gpt4 key购买 nike

需要一个帮助。我想让内部 PHP 脚本在页面加载时自动运行。我遇到与将日期和用户输入的值从表单传递到内部 PHP 脚本有关的问题。我已经尝试了 $_POST$_GET。我应该把脚本放在外部脚本中吗?我真的不需要代码,只是告诉我应该研究什么。谢谢!
进入日志/编辑

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" type="text/javascript" src="js/simpledtpicker.js"></script>
</head>

<body style="text-align:center;">
<div class="wrapper">
<?php include('includes/header.php')?>
<h1 style="text-align:center;">Entry Log/Edit</h1>
<span>
<form action="#" method="GET">
<table style="width:100%;">
<tr>
<th style="text-align:left;">
Entries for:
<input type="text" name="dateOfEntry" class="dateOfEntry">
<script type="text/javascript">
$(function()
{
$('*[name=dateOfEntry]').appendDtpicker(
{
"dateOnly": true,
"dateFormat": "MM/DD/YYYY",
"autodateOnStart": true,
"closeOnSelected": true
});
});
</script>
</th>
<th style="text-align:right; padding-right: 0px;">
User:
<input type="text" name="user" value="Hrobi7198228" readonly="readonly" style="border:none; background-color:transparent"/>
</th>
<th width="5px;"><input type="submit" name="submit" value="Go"></th>
</tr>
</table>
</form>
</span>
<br>
<table class="entry" style="width: 100%;">
<thead>

<?php
include ('connServer.php');

$date = date('Y-m-d', strtotime(str_replace("-","/",$_GET['dateOfEntry'])));
$username = $_GET['user'];

$query = 'SELECT `ID`, `Date`, `Description`, `TypeOfDowntime`, `Machine#` FROM `machineissuesreport` WHERE `Date`="'.$date.'" AND `UpdatedBy` = "'.$username.'" ORDER BY `ID` DESC';

$conn = mysqli_query($connection, $query);

if ($conn)
{
echo '<tr>
<th width="5px">Edit</th>
<th width="5px">Delete</th>
<th>Date</th>
<th>Details</th>
<th width="100px" style="text-align:center;">Downtime Type</th>
<th width="20px" style="text-align:center;">Machine No.</th>
</tr>
</thead>
<tbody>';
while($row = mysqli_fetch_array($conn))
{
echo '<tr>';
echo '<td style="text-align: center" width="5px"><a href="editMachineIssue.php?id='.$row["ID"].'" class="edit">Edit</a></td>';
echo '<td style="text-align: center" width="5px"><a href="#" id="'.$row['ID'].'" class="delete">Delete</a></td>';
echo '<td style="display: none;"><input type="hidden" value='.$row['ID'].'></td>';
echo '<td width="5px" style="text-align: center; padding: 0px 5px;">'.$row['Date'].'</td>';
echo '<td style="text-align: left; padding: 0px 0px 0px 12px;">'.$row['Description'].'</td>';
echo '<td style="text-align: center;">'.$row['TypeOfDowntime'].'</td>';
echo '<td style="text-align: center;">'.$row['Machine#'].'</td>';
echo '</tr>';
}
}


?>

<script type="text/javascript">
$(document).ready(function()
{
$.ajax
({
type: 'POST',
data: {'run':run},
success: function(data)
{
}
});

$('.delete').click(function()
{
if(confirm("Are you sure you want to delete this row?"))
{
var del_id = $(this).attr('id');
var $ele = $(this).parent().parent();

$.ajax({
type: 'POST',
url: 'machineEntryLogEdit.php',
data: {'del_id' : del_id},
success: function(data)
{
$ele.fadeOut().remove();
},
error: function (xhr, status, error)
{
alert(this);
}
});
}
});
});
</script>
</tbody>
</table>
</div>
</body>
</html>

我仍在努力,但请帮我找到正确的 Google 条款。我对 PHP 和 AJAX 还很陌生。

最佳答案

您可以将以下代码写在一个 js 文件中,并将该 js 文件包含在您的页面中。

$(document).ready(function(){
$.ajax({ url: "file.php",
data: data1,
success: function(){
// Do whatever you want to do here.
}});
});

关于PHP 脚本在页面加载时自动运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35738885/

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