Я отправляю запрос GET
.Я обрабатываю данные и получаю ссылку для перенаправления.Я понимаю, что нужно отправить его обратно клиенту и перейти от него.Ссылка действительна.Но по какой-то причине функция не входит в блок is_ajax ()
.
$(document).on('click', '.top_up_pay', function (e) {
var post_data;
e.preventDefault();
var amount = +$('tr.sum > td.price > span.value').text();
var products_id = [];
var products_count = [];
var products_deliv = [];
$.each($('.name'), function(){
var id = $(this).attr('data-product_id');
products_id.push(id);
var count = $(this.parentNode.parentNode.parentNode).find('input[name="count"]');
products_count.push(count.val());
var deliv = $(this.parentNode.parentNode.parentNode).find('.delivery');
products_deliv.push(deliv.val());
})
var new_post = $('.new_post > input')
var ukr_post = $('.ukr_post > input')
var recipient = $('.recipient > input')
var phone = $('.phone > input')
var sum = $('tr.sum > td.price > span.value');
var data = {
products_id: products_id,
products_count: products_count,
products_deliv: products_deliv,
new_post: new_post.val(),
ukr_post: ukr_post.val(),
recipient: recipient.val(),
phone: phone.val(),
sum: sum.text(),
comment: comment,
amount: amount
}
$.ajax({
type: "GET",
url: "/payments/top-up-pay/",
data: data,
crossDomain: true,
success: function(data){
window.location = data.redirect_to
},
error: function(data){
alert('Error') //Error
}
})
setTimeout(function () {
window.location.href = "/products/";
}, 2000);
просмотров
def top_up_pay(request):
template = 'payments/top_up_pay.html'
conf_currency = AppConfig.get_config('subscription_price_currency')
if request.method == "GET":
global req_data
req_data = get_request_data(request)
amount = Decimal(req_data.get('amount'))
if conf_currency:
req_user = request.user
invoice = Invoice.objects.create(
invoice_type=INVOICE_TYPE.TOP_UP,
user=req_user,
amount=amount*100,
currency=conf_currency
)
params = {
"currency": invoice.currency,
"amount": int(invoice.amount),
'order_id': str(70),
"operation_id": str(70),
"order_desc": "payment",
}
integration = FondyIntegration(params)
redirect_to = integration.checkout_url()
if request.is_ajax():
response = HttpResponse(json.dumps({'success': True, 'location': redirect_to}), content_type="application/json")
return response
else:
return redirect(redirect_to)
return render(request, template, ctx)
Ответ: