Question

I want to send information to the screen id that information sent to it by the echo. I get this interaction takes place via ajax would like to receive information from the entire screen again displays. Please help

$(document).ready(function(){
$('#button').click(function(){
    var id = $(this).attr('id_1');

    $.ajax({ 
        url:'get.php',
        type: 'get',
        data:{id:id},
        success: function(data){
        //alert(data);
      $('#result').html(data);
        }

         });
    });
});


  <body>
    <?php if(isset($_GET['id'])){echo $_GET['id'];}?>

    <a href="#" id="button" id_1="20">test</a>
    <div id="result"></div> 

after result

    20
<a>test</a>****------------------------------>Is repeated
<a>test</a>  

but i want just this result

     20
Was it helpful?

Solution 2

Try this. It will displays the output as you said.

    <script type="text/javascript">
    $(document).ready(function(){
    $('#button').click(function(){
        var id = $(this).attr('id_1');

        $.ajax({ 
            url:'get.php',
            type: "get",
            data:{id:id},
            success: function(data){
                $('#result').html(data);
            }

             });
        });
    });

    </script>

    <div id="result">
 <a  href="#" id="button" id_1="20">test</a></div> 

This is get.php

  <?php if(isset($_GET['id'])){echo 'hi';}
  ?>

if you want exit:20 as output, then change get.php as

 <?php if(isset($_GET['id'])){echo 'exit : '.$_GET['id'];}
    ?>

OTHER TIPS

Change you type as GET in AJAX

$('#result').empty();
$.ajax({ 
    url:'get.php?id='+ id,
    type: "GET",
    //data:{id:id},
    success: function(data){
    //alert(data);
  $('#result').html(data);
    }

     });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top