Answer the question
In order to leave comments, you need to log in
What is the best way to write code (ajax)?
Good afternoon, I wrote the code and everything works for me, but it looks bad, can you advise me how to make it better?
$('#input-search').keyup(function(tovar){
let search = $(this).val();
if(search != '')
{
find(search);
}
else
{
find();
}
function find(tovar)
{
$.ajax({
url:"temp/search.php",
method:"POST",
data:{tovar:tovar},
success:function(data)
{
$('.blocktovar').html(data);
$(".viewtovar ").click(function(){
let view = $(this).attr('id');
$.ajax ({
url:"temp/view.php",
method:"POST",
data:{view:view},
success:function (data){
$(".blocktovar").html(data);
}
});
});
}
});
}
});
$(".viewtovar ").click(function(){
let view = $(this).attr('id');
$.ajax ({
url:"temp/view.php",
method:"POST",
data:{view:view},
success:function (data){
$(".blocktovar").html(data);
}
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question