Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(window.XMLHttpRequest){
- xhr = new XMLHttpRequest();
- }
- else if(window.ActiveXObject){
- try{
- xhr = new ActiveXObject('Msxl2.XMLHTTP');
- } catch (e){}
- try{
- xhr = new ActiveXObject('Microsoft.XMLHTTP');
- } catch (e){}
- }
- //var xhr = new XHR();
- var json = JSON.stringify({
- os: jscd.os,
- user_agent:navigator.userAgent,
- referrer:jscd.referrer,
- current_url:jscd.current_url,
- hash:window.hash,
- utm_source:getParameterByName("utm_source"),
- utm_medium:getParameterByName("utm_medium"),
- utm_campaign:getParameterByName("utm_campaign"),
- utm_content:getParameterByName("utm_content"),
- utm_term:getParameterByName("utm_term")
- });
- if(xhr){
- xhr.open("POST", 'http://codes.seosoft.su/api/create', true);
- xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
- xhr.onreadystatechange = function() {
- if (this.readyState != 4) return;
- // по окончании запроса доступны:
- // status, statusText
- // responseText, responseXML (при content-type: text/xml)
- if (this.status != 200) {
- // обработать ошибку
- //alert( 'ошибка: ' + (this.status ? this.statusText : 'запрос не удался') );
- return;
- }
- //console.log(this);
- // получить результат из this.responseText или this.responseXML
- if(this.statusText=="OK"){//get promo-code
- request = JSON.parse(this.responseText);
- //write in cookie
- setCookie("track", request.promo, 30);
- document.getElementById('target-promo').innerHTML = request.promo;
- }
- //console.(log("responseText="+typeof (this.typeof responseText.promo)));
- //console.log("statusText="+this.statusText);
- };
- xhr.withCredentials = true;
- // Отсылаем объект в формате JSON и с Content-Type application/json
- // Сервер должен уметь такой Content-Type принимать и раскодировать
- xhr.send(json);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement