When form submission finishes, the page DISPLAYS the raw json data instead of logging it to the console. The php and html code are both on the same page so I wasn't expecting the page to change at all.
POST
jQuery(function($) {
$("#idSearch").submit(function(event) {
$.ajax({
url: "/index.php",
type: "POST",
data: $(this).serialize(),
dataType: "json",
sucess: function(data) {
console.log(data);
}
})
})
});
php form handling
<?php
if (isset($_POST['orderId'])){
header('Content-Type: application/json');
require 'private/database.php';
$sql = "SELECT * FROM form";
$result = mysqli_query($conn, $sql);
$data = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
}
die(json_encode($data));
}
?><!DOCTYPE html>
I've implemented something similar on another webpage but it works as I intended.
POST
function loadInfo() {
jQuery(function($) {
$.ajax({
method: "POST",
url: "/admin.php",
data: {loadInfo: 1},
dataType: "json",
success: function(data) {
console.log(data);
for (var i = 0; i < data.length; i++) {
setMarker(data, i, "red");
printInfo(data, i);
}
}
})
});
}
php form handling
<?php
if(isset($_POST['loadInfo'])){
header('Content-Type: application/json');
require 'private/database.php';
$sql = "SELECT * FROM form";
$result = mysqli_query($conn, $sql);
$data = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
}
die(json_encode($data));
}
?><!DOCTYPE html>
Why do these two pages behave differently?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…