Здравствуйте, не судите строго я только начинаю свой путь. Имеется страница которая добавляет несколько значений в БД.
var ids = "<? echo $ids; ?>";
$('#editonoff').click(function () {
var $ed = $(this);
if ($ed.is(':checked')) {
$('.EDITPROFILE').show();
$('.dataprf').hide();
$('.editsweeks').show();
$('.weekss').hide();
$('#saveprofile').click(function() {
var Currentweights = document.getElementById("edit1").value;
var Weightbeforepregnancys = document.getElementById("edit2").value;
var tweight = document.getElementById("edit3").value;
var Growths = document.getElementById("edit4").value;
var obg = document.getElementById("edit5").value;
var obr = document.getElementById("edit6").value;
var obt = document.getElementById("edit7").value;
var obj = document.getElementById("edit8").value;
var obbdr = document.getElementById("edit9").value;
var obbr = document.getElementById("edit10").value;
var selectone = document.getElementById("weekk");
var weekbaby = selectone.options[selectone.selectedIndex].value;
var select = document.getElementById("whatababy");
var numchildren = select.options[select.selectedIndex].value;
$.ajax({
type: 'post',
url: 'https://fitness-rocks.me/script_php/editprofile.php',
dataType: "json",
data: {
Growths: Growths,
Currentweights: Currentweights,
Weightbeforepregnancys: Weightbeforepregnancys,
tweight: tweight,
ids: ids,
obg: obg,
obr: obr,
obt: obt,
obj: obj,
obbdr: obbdr,
obbr: obbr,
numchildren: numchildren,
weekbaby: weekbaby
},
success: function(data){
console.log(data);
},
});
document.location.href = "profile.php";
});
}
});
$(document).ready(function () {
var edit = 0;
$.ajax({
type: 'post',
url: 'script_php/editprofile.php',
dataType: "json",
data: {ids: ids},
success: function(data){
console.log(data);
$('#idd1').html(data.arr1);
$('#idd2').html(data.arr2);
$('#idd3').html(data.arr3);
$('#idd4').html(data.arr4);
$('#idd5').html(data.arr5);
$('#idd6').html(data.arr6);
$('#idd7').html(data.arr7);
$('#idd8').html(data.arr8);
$('#idd9').html(data.arr9);
$('#idd10').html(data.arr10);
},
});
});
Сюда отправляю данные со страницы и записываю их.
<?php
require "../db.php";
$growths = $_POST['Growths'];
$currentweights = $_POST['Currentweights'];
$weightbeforepregnancys = $_POST['Weightbeforepregnancys'];
$tweight = $_POST['tweight'];
$idss = $_POST['ids'];
$obg = $_POST['obg'];
$obr = $_POST['obr'];
$obt = $_POST['obt'];
$obj = $_POST['obj'];
$obbdr = $_POST['obbdr'];
$obbr = $_POST['obbr'];
$numchildren = $_POST['numchildren'];
$weekbaby = $_POST['weekbaby'];
$editprof = R::load('users', $idss);
if ( $currentweights != '' ){
$editprof->currentweights = $currentweights;
}
if( $weightbeforepregnancys != '' ){
$editprof->weightbeforepregnancys = $weightbeforepregnancys;
}
if( $tweight != '' ){
$editprof->tweight = $tweight;
}
if( $growths != '' ){
$editprof->growths = $growths;
}
if( $obg != '' ){
$editprof->obg = $obg;
}
if( $obr != '' ){
$editprof->obr = $obr;
}
if( $obt != '' ){
$editprof->obt = $obt;
}
if( $obj != '' ){
$editprof->obj = $obj;
}
if ( $obbdr != '' ){
$editprof->obbdr = $obbdr;
}
if ( $obbr != '' ){
$editprof->obbr = $obbr;
}
if ( $numchildren != 0 ){
$editprof->numchildren = $numchildren;
}
if ( $weekbaby != 0 ){
$editprof->weekbaby = $weekbaby;
}
R::store($editprof);
$tekves = $editprof->currentweights;
$vesdober = $editprof->weightbeforepregnancys;
$celves = $editprof->tweight;
$rost = $editprof->growths;
$obgrudi = $editprof->obg;
$obruki = $editprof->obr;
$obtalii = $editprof->obt;
$objivota = $editprof->obj;
$obbeder = $editprof->obbdr;
$obbedra = $editprof->obbr;
$nedels = $editprof->weekbaby;
$numberkinder = $editprof->numchildren;
$beremenna = $editprof->pregnant;
$name = $editprof->name;
$data = ['arr1' => $tekves, 'arr2' => $vesdober, 'arr3' => $celves, 'arr4' => $rost, 'arr5' => $obgrudi, 'arr6' => $obruki, 'arr7' => $obtalii, 'arr8' => $objivota, 'arr9' => $obbedra, 'arr10' => $obbeder];
echo json_encode($data);
?>
Собственно при нажатии на кнопку #saveprofile происходит перезагрузка страницы, после чего, не всегда выводятся новый данные с БД приходиться повторно перезагружать страницу, а порой и со второй перезагрузки страницы данные не обновляются.