Есть запрос для автозаполения формы jQuery, но при нем выбивает ошибку “has been blocked by CORS policy”, искал решения, но работающего решения пока никак не смог найти…:
$(“#pick-up_from”).autocomplete({
source : function(request, response) {
$.ajax({
url : 'https://www.transfermilan.com/ajax.html',
data : "json",
method : 'post',
data : {
term : request.term,
action : 'search_form_tarif',
row_num : 1
},
success : function(data) {
response($.map(data, function(item) {
var code = item.split("|");
//alert(code);
return {
label : code[0],
value : code[0],
data : item
}
}));
}
});
},
minLength: 2,//search after two characters
select : function(event, ui) {
var names = ui.item.data.split("|");
$('#direction_from').val(names[1]);
//
$('.loading_from').hide();
},
search : function(event, ui) {
$('.loading_from').show();
},
focus : function(event, ui) {
$('.loading_from').hide();
},
});
$(“#pick-up_to”).autocomplete({
source : function(request, response) {
$.ajax({
url : 'https://www.transfermilan.com/ajax.html',
dataType : "json",
method : 'post',
data : {
term : request.term,
action : 'search_form_tarif',
row_num : 1
},
success : function(data) {
response($.map(data, function(item) {
var code = item.split("|");
return {
label : code[0],
value : code[0],
data : item
}
}));
}
});
},
minLength: 2,//search after two characters
select : function(event, ui) {
var names = ui.item.data.split("|");
$('#direction_to').val(names[1]);
},
search : function(event, ui) {
$('.loading_to').show();
},
focus : function(event, ui) {
$('.loading_to').hide();
},
});
// zagrygaem spiski gorodov
$(“#country_from, #country_to”).change(function () {
var id = $(this).attr("id");
if(id == 'country_from'){
var dest = 'direction_from';
}
else {
var dest = 'direction_to';
}
$("#" + dest).hide();
$("#loading_" + dest).show(); // запускаем
var ajax_url = 'https://www.transfermilan.com/ajax.html';
$.post(ajax_url, { action: 'direction_from', id: $(this).val() }, updateFild);
function updateFild(data) {
$('#' + dest).html(data);
$("#" + dest).show();
$("#loading_" + dest).hide(); // скрываем загрузку
$('#orderForm').validate().element($('#' + dest)); //проверяем на валидность
$('#orderForm').validate().element(this); //проверяем на валидность
}
});
// pokazivaem dopolnitelnie polja dlja viezda zagranizy
$(“#direction_from, #direction_to”).change(function () {
var type = $(this).attr("id");
var ajax_url = 'https://www.transfermilan.com/ajax.html';
$.post(ajax_url, { action: 'direction_type', id: $(this).val() }, showTypeFild);
$('#orderForm').validate().element(this);
function showTypeFild(data) {
//from
if(type == 'direction_from'){
if(data == 2){
$('#city_from_filds').hide();
$('#airport_from_filds').show();
}
else {
$('#city_from_filds').show();
$('#airport_from_filds').hide();
}
}
//to
else {
if(data == 2){
$('#city_to_filds').hide();
}
else {
$('#city_to_filds').show();
}
}
}//function
});