inicial.php:
$(document).ready(function(){$("button").click(function(){var teste = $("#teste").val();alert(teste);$.ajax({url: "function.php",type: "POST",data:{teste:teste},success: function(result){alert(result);$("#div1").html(result);}});});});function cade(){var form = $("#form").serialize();var action = "cade";alert(form+'/ '+action);$.ajax({url: "cade.php",type: "POST",dataType: "json",data: form,success: function(result){alert(result);}});}Get External Content<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var teste = $("#teste").val();
alert(teste);
$.ajax({
url: "function.php",
type: "POST",
data: {
teste:teste
},
success: function(result){
alert(result);
$("#div1").html(result);
}});
});
});
</script>
<script>
function cade(){
var form = $("#form").serialize();
var action = "cade";
alert(form+' / '+action);
$.ajax({
url: "cade.php",
type: "POST",
dataType: "json",
data: form,
success: function(result){
alert(result);
}});
}
</script>
</head>
<body>
<input type="text" id="teste" name="teste" value="" />
<button>Get External Content</button>
<br><br>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
</body>
</html>
Let jQuery AJAX Change This Text
function.php:
";echo "";echo "";echo "SERIAL";echo "EQUIPAMENTO";echo "FOTO";echo "";while($result = mysqli_fetch_array($select)){echo "";echo "";echo "";echo "";echo "";}echo "";<?php
$con = @mysqli_connect("localhost",'root','','test')or die("erro no banco");
$teste = @$_POST['teste'];
$select = @mysqli_query($con,"SELECT * FROM test.teste where serial = '$teste' ") or die ("erro na query 2");
echo "<form id='form' name='form' method='post' action='' >";
echo "<table border='1'>";
echo "<tr>";
echo "<th>SERIAL</th>";
echo "<th>EQUIPAMENTO</th>";
echo "<th>FOTO</th>";
echo "</tr>";
while($result = mysqli_fetch_array($select)){
echo "<tr>";
echo "<td><input type='text' value='".$result['serial']."' id='serial' name='serial'/></td>";
echo "<td><input type='text' value='".$result['equipamento']."' id='eq' name='eq' /></td>";
echo "<td><input type='text' value='".$result['foto']."' id='foto' name='foto' /></td>";
echo "</tr>";
}
echo "</table>";
?>
<input type="button" value="Cadastrar" onclick="cade();" />
</form>
?>cade.php:
window.history.back();";?><?php
$con = @mysqli_connect("localhost",'root','','test')or die("erro no banco");
$serial = $_REQUEST['serial'];
$eq = $_REQUEST['eq'];
$foto = $_REQUEST['foto'];
print_r(@$_POST);
$inseri = @mysqli_query($con,"insert into test.nova (serial,equipamento,foto) values ('$serial','$eq','$foto') ") or die ("erro na query");
//echo "<script>window.history.back();</script>";
?>