app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header('Access-Control-Allow-Credentials', 'true');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var ajaxSettings = {
method: form.method,
url: form.action,
data: JSON.stringify(data),
// dataType: form.method === 'get' ? 'jsonp' : 'json',
dataType: 'json',
contentType: 'application/json',
processData: false,
xhrFields: {
withCredentials: true
}
};
var ajaxRequest = $.ajax(ajaxSettings);
jQuery.getJSON('/ajaxlogin/', {login:login, pass:pass}, function(result){
if (result.redirect) {
window.location = result.redirect
} else if (result.error) {
alert(result.error);
}
});
....
if (ok) {
return res.json({redirect: 'authorizationSuccess.html'})
} else {
return res.json({error: 'authorization fail!'})
}
....
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", req.headers.origin);
res.header('Access-Control-Allow-Credentials', 'true');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
для node.js + expressvar ajaxSettings = {
method: form.method,
url: form.action,
data: JSON.stringify(data),
dataType: 'json',
contentType: 'application/json',
processData: false,
xhrFields: {
withCredentials: true
}
};
var ajaxRequest = $.ajax(ajaxSettings);
...
для jquery function checkPhone(phoneNumber) {
return new Promise(function(resolve, reject) {
var client = telegramLink.createClient(app, datacenter, () => {
client.createAuthKey((auth) => {
client.auth.checkPhone(phoneNumber, (result) => {
resolve(result);
});
});
});}
);
};
checkPhone(phone2).then(
(result)=>{console.log('result', result);},
(error)=>{console.log('error', error);}
);
setTimeout(()=>{}, 20000);