Answer the question
In order to leave comments, you need to log in
How to pass value to window.location?
There is a list of models. By clicking on the model, a form opens, after submitting the form, the file is automatically downloaded. This moment works (with manually written window.location), but I need to click on the model, pass the value from the link attribute a href="" to window.location
$(document).on('submit','#ajaxForm form',function(ev){
var frm = $('#ajaxForm form');
$.ajax({
type: 'post',
url: '/form6',
data: frm.serialize(),
success: function (data) {
$('#ajaxForm form').remove();
$('#ajaxForm').html( data );
window.location= '';
}
});
ev.preventDefault();
})
$(document).ready(function(){
$('a.mod').click(function() {
$(".par1")
var sup = ($(this).attr('title2'));
$(".par1").html(sup);
});
});
<div class="model">
<a href="#modal" title2="http://ссылка на файл">Название модели</a>
</div>
Answer the question
In order to leave comments, you need to log in
It turned out like this:
$(document).ready(function(){
$('a.mod').click(function() {
$(".par1")
var sup = ($(this).attr('title2'));
$('#ajaxForm').attr('title3', sup)
});
});
$(document).on('submit','#ajaxForm form',function(ev){
var frm = $('#ajaxForm form');
$.ajax({
type: 'post',
url: '/form6',
data: frm.serialize(),
success: function (data) {
$('#ajaxForm form').remove();
$('#ajaxForm').html( data );
var sup2 = $('#ajaxForm').attr('title3');
window.location= sup2;
}
});
ev.preventDefault();
})
document.addEventListener('click', linksHandler); // слушаем все клики
function linksHandler(evt) {
// проверяем, были ли клик по ссылке с title2 или по элементу внутри такой ссылки
const link = evt.target.closest('[title2]');
if (link) {
const title2 = link.getAttribute('title2');
console.log(link);
console.log(title2);
// передавай что хочешь
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question