I'm developing a site that takes data from a certain location and when I click the button it has to save somewhere else and for this I'm using Jquery but I'm not able to save it to my bank. Someone can help me.
code that after the content
$(document).ready(function(){
$.getJSON("myonsala", function(result){
$("form div.online").empty();
$.each(result, function(i, field){
$("form div.online").append("<div class=\"user impar\">" + "<figure>" + "<img src=\"img/users/Profiles/"+field.foto+"\">" +
"</figure>"+"<span class=\"nickname\">"+field.Ninck +"<span class=\"cartaoAmarelo cartaoAmarelo0\">"+"</span>"
+"</span>"+"<p class=\"desafiar\" onclick=\"desafio();\">"+" DESAFIAR!"+"<input name=\"desafiado\" type=\"hidden\" value="+field.Id+">"+
" </p>"+ "</div>");
});
$("span#onsala").empty();
$("span#onsala").append(result.length);
});
});
else you have to get the value that comes from the field desafiado
and send it to php page for it.
php page:
if(isset($_POST['desafiado'])){
if(isset($_SESSION['sala'])){
if(isset($_SESSION['tkm'])){
$desafiado = $_POST['desafiado'];
//$desafiado=16;
$sala=$_SESSION['sala'];
$tkm=$_SESSION['tkm'];
$results = DB::select("SELECT Id,Ninck FROM usuarios WHERE Has='$tkm'");
foreach($results as $row){
$Id=$row->Id;
$Nick=$row->Ninck;
}
$results = DB::select("SELECT Ninck FROM usuarios WHERE Id='$desafiado'");
foreach($results as $row){
$Nickop=$row->Ninck;
}
$results = DB::select("SELECT s.Valor as valors FROM onsalas o,salas s WHERE o.Idsala=s.Id");
foreach($results as $row){
$valor=$row->valors;
}
//dd($valor);
$cron = '02:40';
$date =date('Y-m-d H:i:s');
$datec = date('Y-m-d');
$horac= date('H:i:s');
$inserir= DB::table('Partidas')->insert(
['IdDesafiante'=>$Id,'NickDesafiante'=>$Nick,'IdDesafiado'=>$desafiado,'NickDesafiado'=>$Nickop,'Aceitou'=>0,'CronDesafiante'=>$cron,'CronDesafiado'=>$cron,'Valor'=>$valor,'IdSala'=>$sala,'CanceladoPreJogo'=>0,'IdCanceladorPreJogo'=>0,'Motivo'=>0,'AbamdonarPartida'=>0,'IdAbandonarPartida'=>0,'Divegencia'=>0,'DataCriacao'=>$datec,'HoraCriacao'=>$horac,'HoraAceito'=>0,'HoraFimPrejogo'=>0,'HoraFinal'=>0,'updated_at'=>$date,'created_at'=>$date]
);
dd($inserir);
$banco='f';
return response()->json($banco);
}else{
echo "erro1";
}
}else{
echo "erro3";
}
}else{
echo "erro3";
}
Someone can help me. I'm using jquery because I can not submit the page because I do not want it reloaded.
update on 07/16/2018 using ajax
function desafio(){
$('form').submit(function(e){
e.preventDefault();
var data=$(this).serializeArray();
$.ajax({
url: "desafio",
type: "post",
dataType: "json",
data: data,
})
.done(function() {
alert( "success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
});
})
}
Now it gives the supmit however as GET and in the page that I am in the page that I put for it to go