0

how do I get this ajax value #name and store it in a php variable? what i have done is put it in a HTML.

<p id="name"></p>


    setInterval(function(){

    $.ajax({
        url:"count.php", 
        type:"GET", 
        async:true, 
        cache:false, 
        success:function(count)
        {
            $("#name").html(count);

        }
    });

},1000);
Jk Asentista
  • 35
  • 1
  • 6
  • Possible duplicate of [jquery - return value using ajax result on success](http://stackoverflow.com/questions/3302702/jquery-return-value-using-ajax-result-on-success) – Milan Malani Sep 25 '16 at 08:25

1 Answers1

0

Use data to pass the variable to server. i.e. to count.php

 <p id="name"></p>
        setInterval(function(){
        var name=$("#name").val();
        $.ajax({
            url:"count.php",
            data:{name:name}, 
            type:"GET", 
            async:true, 
            cache:false, 
            success:function(count)
            {
               var res = $.parseJSON(count);
               var result= res.name;
               $("#name").html(result);
            }
        });

    },1000);

And in count.php

   $name=$_GET['name'];
   echo json_encode(array('status'=>TRUE,'name'=>$name));die;
Sanzeeb Aryal
  • 4,358
  • 3
  • 20
  • 43