Answer the question
In order to leave comments, you need to log in
If using ajax to transfer json to php, then how to use this json in the Handlebars template in the future?
$(document).ready(function(){
$('form').submit(function(){
event.preventDefault();
var order = $(this).serialize();
$.ajax({
url: "action.php",
type: "post",
dataType: "json",
data: order,
success: function(data){
if(data.result == "ok"){
$('.messages').html("<span style='color: green; background: white'>Сообщение успешно отправлено!</span>");
$('#user_name').val('');
$('#user_email').val('');
$('#text_comment').val('');
var template = Handlebars.compile( $('#template').html() );
//пытаюсь передать значения через переменную order, но так не передаёт
$('.updates').append( template(order) );
}else{
$('.messages').html(data.result);
}
}
});
});
});
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