私は自分の人生でそれを理解することができないので、ここでお尻を蹴っています. jQuery の AJAX メソッドの経験がないため... AJAX 呼び出しを適切に実装する方法を学び、理解するために文字通り 5 日間を費やしましたが、役に立つことを知るために...基本的なことを学びましたが、必要なことは学びませんでした。以下のコードを実行します。
繰り返しますが、jQueryを使用してこの標準リクエストをAJAXに変換する方法を考えています...
ここに私のフォームとPHPがあります
HTML:
<form action="categories.php?action=newCategory" method="post">
<input name="category" type="text" />
<input name="submit" type="submit" value="Add Categories"/>
</form>
PHP:
<?php
if (isset($_POST['submit'])) {
if (!empty($_POST['category'])) {
if ($_GET['action'] == 'newCategory') {
$categories = $_POST['category'];
$query = "SELECT * FROM categories WHERE category ='$categories' ";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result)) {
echo '<script>alert("The Following Catergories Already Exist: ' . $categories . '")</script>';
} else {
// Simply cleans any spaces
$clean = str_replace(' ', '', $categories);
// Makes it possible to add multiple categories delimited by a comma
$array = explode(",", $clean);
foreach ($array as &$newCategory) {
mysql_query("INSERT INTO categories (category) VALUES ('$newCategory')");
}
echo "<script>alert('The following Categories have been added successfully: " . $categories . "')</script>";
}
}
} else {
echo "<script>alert('Please Enter at Least One Category.')</script>";
}
}
?>