-1

I'm unable to understand these answers Question1 Question2 Question3 so posting my question.
I'm sending an Ajax request in PHP file:

$(document).ready(function(){
    $(document).on('click','.show_more',function(){
        var ID = 10;
        var USERID =1;
        $('.show_more').hide();
        $('.loding').show();
        $.ajax({
            type:'POST',
            url:'/ajaxload.php',
            data:'id='+ID & 'user_id=' + USERID,
            success:function(html){
                $('#show_more_main'+ID).remove();
                $('.post_list').append(html);
            }
        }); 
    });
});

while receiving Ajax URL id is received successfully but user_id is not getting received

<?php 
if(isset($_POST["id"]) && ($_POST["user_id"]) && !empty($_POST["id"])){
    echo $_POST["id"];
    echo $_POST["user_id"];
} 
?>
1
  • thank you @dlmeetei for improve my questions Commented Aug 6, 2017 at 10:29

2 Answers 2

3

Replace :

data:'id='+ID & 'user_id=' + USERID,

with:

data: {id:ID, user_id:USERID}

so your code will look like this :

$(document).ready(function(){
    $(document).on('click','.show_more',function(){
        var ID = 10;
        var USERID =1;
        $('.show_more').hide();
        $('.loding').show();
        $.ajax({
            type:'POST',
            url:'/ajaxload.php',
            data: {id:ID, user_id:USERID},
            success:function(html){
                $('#show_more_main'+ID).remove();
                $('.post_list').append(html);
            }
        }); 
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

you welcome @BrijeshPatel and thank as well for acceping the answer
when i send VARCHAR then it's not working like USERID = "us1"; data: {id:ID, user_id:USERID}, this line is right or where i'm missing some step
0

pass the data as javascript objects

data:{
  id:ID,
  user_id:USERID
}

2 Comments

when i send VARCHAR then it's not working like USERID = "us1"; data: {id:ID, user_id:USERID}, this line is right or where i'm missing some step please help
Could you give a little more info about the problem? @Brijesh Patel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.