我写了有关库存管理的代码。
我有文件:
index.php
数据库-> 包含我的所有代码文件
当我从localhost / Stock / database / test.php运行代码时enter image description here
它运行完美,可以将带有操作/发布的信息无问题地传输到另一个代码文件。
并显示此enter image description here
然后我在index.php中包含test.php。
我运行,这次是localhost / Stock enter image description here
显示相同的图像enter image description here
但是这次不起作用!
以下代码:
Index.php
<?php include 'database/database_connection.php'; ?>
<!DOCTYPE html>
<html lang="en">
<body>
<?php
include 'database/test.php';
?>
</body>
</html>
test.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function(){
$("#submit").click(function(){
var barcode = $("#kwdikos").val();
var value = $("#timi").val();
$.post("ajax.php",
{
barcode: barcode ,
value: value
},function(data){
$("#test").html(data);
});
});
});
</script>
</head>
<body>
<input type="text" id="kwdikos" placeholder="Εισαγωγή BarCode">
<input type="text" id="timi" placeholder="Εισαγωγή Ποσότητας">
<input type="submit" id="submit" value="Προσθήκη">
<p id="test"></p>
<form action="stock_management.php" method="POST">
<button id="btn1">Συνέχεια</button>
</form>
</body>
</html>
我已修复。
如果有人遇到相同的问题。
只需更改代码的位置。
将Ajax放在head
内
并删除ajax的引导程序链接。
也在post方法中,操作是database/ajax.php
,因为当我包含在index.php中时,ajax.php位于不同的文件夹中