0

I am Getting Following Error Undefined index: userLoggedIn in C:\xampp\htdocs\HamdardSocial\includes\handler\ajax_load_posts.php AJAX Code to Fetch data from ajax_load_posts.php

<script>
var userLoggedIn = '<?php echo $userLoggedIn; ?>';

$(document).ready(function() {

    $('#loading').show();

    //Original ajax request for loading first posts 
    $.ajax({
        url: "includes/handler/ajax_load_posts.php",
        type: "POST",
        data: "page=1&userLoggedIn=" + userLoggedIn,

        cache:false,

        success: function(data) {
            $('#loading').hide();
            $('.posts_area').html(data);

        }
    });

});

</script>`

I have also tried using POST and REQUEST method but no success Code of ajax_load_posts.php

<?php

include ('../../config/config.php') ;
include ('../classes/User.php') ;
include ('../classes/Post.php') ;

$limit=10;

$posts = new Post($conn, $_POST['userLoggedIn']);
$posts->loadPostsFriends();


?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    Don't trust the client to tell you who they are. Somebody could spoof another user simply by hitting `/path/to/page?page=1&userLoggedIn=12345`. You should pull the userid out of the session on the server side. – Alex Howansky Jan 04 '19 at 21:45

1 Answers1

0

To send data by jQuery's $.ajax is necessary to format the data field.

Example:

...
$.ajax({
       url: "includes/handler/ajax_load_posts.php",
       type: "POST",
       data:{
          page: "1",
          userLoggedIn: userLoggedIn
       },
...

More information can be found here.

But follow that @Alex Howansky said, it's important for the system security.

I hope it helps...

MarcosAM
  • 79
  • 6