Answer the question
In order to leave comments, you need to log in
What is the best way to send/receive data with ajax?
A bit confused when working with ajax.
Specifically - about how and where the result is returned.
Part of the code
$.ajax({
url: 'actions.php?show,success: function(data){$('#input_area').html(data);}
});
function show($show)
{
echo '<div id="input_area"><a href="#" class="link">Link</a></div>';
}
<div>echo show(''); </div>
<div>
<div id="input_area">
<a href="#" class="link">Link</a>
</div>
</div>
function show($show)
{
echo '<a href="#" class="link">Link</a>';
}
<div id="input_area"> echo show(''); </div>
Answer the question
In order to leave comments, you need to log in
It is difficult to understand what the task is. What should be done?
$.ajax({
url: "some.php", // адрес куда отправляем запрос
success: function(data){
alert( "Прибыли данные: " + data ); // data можем вставлять в любое место $('#element_id').html(data);
}
});
As I understand it, the result will be returned to the element with id=input_area.
$.ajax({
url: 'actions.php?show',
success: function(data){ // <-- сюда вернутся данные из скрипта php, попав в data
$('#input_area').html(data); // здесь они будут вставлены в соответствующий DOM элемент
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question