edit
Trying to explain it again since my previous explanation was left unclear.
What I am trying to do is simple in theory, but I cannot make it work. I have six pages:
- searchnanny.js
- superhoidja.js
- nannyInfo.php
- searchNanny.php
- superhoidja.php
- search.php
The flow should be like this is like this:
- I query user information from database on
searchNanny.php
- on
searchNanny.js
I use$.getJSON("PHP/scripts/searchNanny.php", function (data) {});
to append the list of all users to a div on pagesearch.php
- User clicks on the generated
href="superhoidja.php?superhoidja_id='+data.user_id+'"
on pagesearch.php
which takes them to a page calledsuperhoidja.php
as well should send thedata-id
to a page calledsuperhoidja.js
on redirect (don't know if this is possible) - On the page
superhoidja.php
I include the js filesuperhoidja.js
which includes the following$.getJSON("PHP/scripts/nannyInfo.php", function (data) { console.log(data);});
Now the problem is that I never get the data-id
on nannyInfo.php
because of the redirect I guess. If I don't redirect, I get all the information.
I tried to use $_GET
on superhoidja.php file and it worked fine. Then pass the ID to the nannyInfo.php
, but that still does not work- cannot get the ID (see example below).
I would like to pass the data-id
to the nannyInfo.php
on searchNanny.js
because then I don't have any JS on the superhoidja.php
file where comes my question: How can I pass the data-id
from searchNanny.js
to nannyInfo.php
and get all the data on superhoidja.php
via superhoidja.js
?
I hope this explanation is clearer and makes sense. If somebody knows a easier work flow then please tell me. Thanks in advance.
List point 2 example is here:
var profileCard =
' <div class="col-md-3">'+
' <div class="card hovercard">'+
' <div class="cardheader">'+
' </div>'+
' <div class="avatar">'+
' '+profilePictureString+''+
' </div>'+
' <div class="info">'+
' <div class="title">'+
' <p>'+data.userFirstName+' '+userLastNameLetter+'.</p>'+
' </div>'+
' <div class="desc">'+data.description+'</div>'+
' </div>'+
' <div class="bottom">'+
' <a class="btn btn-primary userProfile" href="superhoidja.php?superhoidja_id='+data.user_id+'" data-id="'+data.user_id+'">'+
' <i class="fa fa-search" aria-hidden="true"></i> Vaata'+
' </a>'+
' </div>'+
' </div>'+
' </div>';
$("#nannySearchListing").append(profileCard);
List point 3 example
Tried to send the ID like this:
$(document).on("click", ".userProfile", function (e) {
var superhoidja_id= $(this).data('id');
console.log(superhoidja_id);
$.ajax({
type: "POST",
url: 'PHP/scripts/nannyInfo.php',
data: "superhoidja_id=" + superhoidja_id,
success: function (data) {
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown, data) {
console.log(jqXHR, textStatus, errorThrown, data);
}
});
});
Superhoidja.php page example what I tried
//get the id from the page
$superhoidja_id = $_GET['superhoidja_id'];
$(document).ready(function(){
var superhoidja_id = <?php echo $superhoidja_id ?>;
console.log(superhoidja_id);
$.ajax({
url: "PHP/scripts/nannyInfo.php",
type: "POST",
data: superhoidja_id
});
});
nannyInfo.php
<?php
header('Content-type: application/json;charset=utf-8');
require_once '../class.user.php';
$user_home = new USER();
if (empty($_SESSION['userSession'])){
die();
}else{
if(isset($_POST['superhoidja_id'])){
$superhoidja_id = $_POST['superhoidja_id'];
}else{
die();
}
}
?>