Answer the question
In order to leave comments, you need to log in
Ajax Post request without page reload?
I'm trying to send a post-request on one page without reloading, ajax works ok, everything is sent to the console. But for some reason php doesn't want to output.
Code like this:
Button:
<a href="#" class="btn-edit" id="<?php echo $user['id']; ?>" onclick="give(this.id)"></a>
$(document).ready(function( ){
$('div a').click(function() {
$.ajax({
type: "POST",
url: "singers.php",
data: "idart="+this.id,
})
})
})
echo $_POST['idart'];
Answer the question
In order to leave comments, you need to log in
Where is the function give(this.id)
? And why is it, if you are already onclick
hanging a handler on the event through jQuery?
PS
<?php if(empty($_POST['idart'])): $user['id'] = 'tosterUser'; ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#user_link').click(function(){
$.post({
url: 'testo.php',
data: 'idart=' + $(this).attr('data-id'),
success: function(data){ $('#result').append('<br>' + data); }
})
});
});
</script>
<div id="result"><a href="#" id="user_link" data-id="<?php echo $user['id']; ?>">Кнопка</a></div>
<?php else: echo $_POST['idart']; endif; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question