Друзья, портирую расширение из Chrome на Firefox. У FF много своих особенностей с которыми нужно как то найти общий язык. Например, мне нужно отправить ajax запрос типа post, который в хроме работает, а в firefox не хочет, при чем не выдает никакой ошибки в консоле, просто доходит до этого куска и типа дальше ничего нет. Я новичок в веб-разработке, мой профиль десктоп C#.
Тестируется на Firefox Developer Edition 55.0b7 (64-біт).
Привожу код, который отказывается работать:
function getValues(callback) {
console.log('getvalues');
browser.runtime.sendMessage({
method: 'getParams'
}, function(response) {
callback(JSON.parse(response.data));
});
}
function setPageData(extValues) {
console.log('SETPAGEDATA');
var resumes = document.getElementsByClassName('card');
var numberTypes = /\d+/;
var idArray = new Array();
if (document.getElementsByTagName('nav').length == 1) {
console.log('if (document.getElementsByTagName(nav).length == 1)');
return;
}
for (i = 0; i < resumes.length; i++) {
var resume = resumes[i].getElementsByTagName('a')[0];
if (resume !== undefined) {
console.log(' if (resume !== undefined)');
var href = resume.getAttribute('href');
if (href !== null) {
console.log(' if (resume !== undefined)');
var id = resume.getAttribute('href').match(numberTypes);
if (id !== null) {
console.log(' if (id !== null)');
idArray.push(id[0]);
}
}
}
}
console.log(extValues.webServicePath);
console.log(extValues.Login);
console.log(idArray);
$.ajax({
type: 'POST',
asyns: false,
contentType: 'application/json; charset=windows-1251',
dataType: 'json',
url: extValues.webServicePath,
data: JSON.stringify({
calcId: 'CANDIDATE.INWORKUA',
args: JSON.stringify({
form: {
ids: idArray,
userid: extValues.Login
}
}),
ticket: ''
}),
success: function(data, event) {
event.preventDefault();
console.log('success');
var valuesIn = JSON.parse(data.d);
for (i = 0; i < resumes.length; i++) {
var resume = resumes[i].getElementsByTagName('a')[0];
currentId = 0;
if (resume !== undefined) {
console.log('success');
if(resume.getAttribute('role') == 'button') {
continue;
}
if(resume.getAttribute('id') == 'changeCat'){
continue;
}
var href = resume.getAttribute('href');
if (href !== null) {
var id = resume.getAttribute('href').match(numberTypes);
if (id !== null) {
currentId = id[0];
}
}
}
var node = resumes[i].getElementsByTagName('a')[0];
if (node == undefined) {
continue;
}
var parentSpan = document.createElement('span');
parentSpan.className = extValues.lblId;
var span = document.createElement('span');
if (valuesIn.IN.indexOf(currentId) !== -1) {
span.setAttribute('style', 'color:' + extValues.ProfileColor + ';font-size:small');
span.appendChild(document.createTextNode(extValues.ProfileIn));
console.log('if span.setAttribute, span.appendChild');
} else {
span.setAttribute('style', 'color:' + extValues.AddColor + ';font-weight: bold;font-size:small');
span.appendChild(document.createTextNode(extValues.NotIn));
console.log('else span.setAttribute, span.appendChild');
}
var img = document.createElement('img');
console.log('image');
//img.src = browser.extension.getURL(extValues.MainImage);
img.setAttribute('src',browser.extension.getURL(extValues.MainImage));
console.log('img.src = browser.extension.getURL');
var mainSpan = document.createElement('span');
mainSpan.appendChild(document.createTextNode(extValues.lblId));
mainSpan.setAttribute('style', 'color:' + extValues.MainColor + '; font-family:' + extValues.MainFont + ';font-weight: bold;font-size:medium');
parentSpan.appendChild(span);
parentSpan.appendChild(img);
parentSpan.appendChild(mainSpan);
parentSpan.appendChild(document.createElement('br'));
node.insertBefore(parentSpan, node.firstChild);
console.log(' node.insertBefore(parentSpan, node.firstChild);')
}
}
});
}
getValues(setPageData);
console.log('getValues');
На моменте
$.ajax({
type: 'POST',
прекраащается работоспособность. Но, если в консоле написать вот так
$.ajax({
type: 'POST',
contentType: 'application/json; charset=windows-1251',
dataType: 'json',
url: 'https://m.it.ua/ws/WebService.asmx/ExecuteEx',
data: JSON.stringify({
calcId: 'CANDIDATE.INWORKUA',
args: JSON.stringify({
form: {
ids: idArray
}
}),
ticket: ''
}),
success: function(data) { console.log(data)},
error: function(data) { console.log('nix_ne-ok-')}
});
Запрос посылается и все отрабатывает. Кто сталкивался с подобным, помогите. Уже ума не приложу, что он хочет. Понимаю, что загвоздка в одном ньюансе, а найти его не могу, так как прошагать код в отладке (как я обычно в студии делаю) возможности нет, а Firebug никаких ошибок не выдает.
Заранее благодарен)
P.S: async : false не помогает.
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости