Answer the question
In order to leave comments, you need to log in
How to change url on ajax form submission?
Code for submitting the form to add an order
$js = <<<JS
$('form').on('beforeSubmit', function(){
var data = $(this).serialize();
$.ajax({
url: '/order/default/add-order',
type: 'POST',
data: data,
success: function(response){
$('#basket').html(response);
},
error: function(){
alert('Error!');
}
});
return false;
});
JS;
$this->registerJs($js);
<?= Html::a('<i class="glyphicon glyphicon-shopping-cart"></i>', ['/order/default/add-order'], [
'class' => 'btn btn-default pull-right',
'data-toggle' => 'tooltip',
'data-placement' => 'bottom',
'title' => 'Добавить заказ в корзину',
'data' => [
'confirm' => 'Вы уверены?',
'data-method' => 'post',
],
]) ?>
<?= Html::a('<i class="glyphicon glyphicon-trash text-danger"></i>', ['/order/default/delete-order', 'id' => $order->id], [
'data-toggle' => 'tooltip',
'data-placement' => 'bottom',
'title' => 'Удалить заказ из корзины',
'data' => [
'confirm' => 'Вы уверены?',
'data-method' => 'get',
],
]) ?>
Answer the question
In order to leave comments, you need to log in
Good afternoon.
<?= Html::a('<i class="glyphicon glyphicon-trash text-danger"></i>', ['/order/default/delete-order', 'id' => $order->id], [
'data-toggle' => 'tooltip',
'data-placement' => 'bottom',
'title' => 'Удалить заказ из корзины',
'data' => [
'confirm' => 'Вы уверены?',
'data-method' => 'get',
'delete-url' => Url::to('/order/default/delete-order');
],
]) ?>
$('form').on('beforeSubmit', function(){
var data = $(this).serialize();
var url = $(selector).attr('data-delete-url');
$.ajax({
url: url,
type: 'POST',
data: data,
success: function(response){
$('#basket').html(response);
},
error: function(){
alert('Error!');
}
});
return false;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question