Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(widget_container.dataset.loaded == "false"){
  2.             var id     = widget_container.dataset.squirrelId;
  3.             var make   = widget_container.dataset.make;
  4.             var model  = widget_container.dataset.model;
  5.             var domain = window.location.origin;
  6.  
  7.             var amp = widget_container.querySelector('amp-iframe');
  8.             if(amp != null)
  9.                 amp.remove();
  10.  
  11.             if(!id && (!make || !model))
  12.                 return;
  13.  
  14.             if(!id){
  15.                 var data = new FormData();
  16.  
  17.                 data.append("make", make);
  18.                 data.append("model", model);
  19.                 data.append("domain", domain);
  20.                 data.append("href", window.location.href);
  21.  
  22.                 var xhr = new XMLHttpRequest();
  23.  
  24.                 xhr.addEventListener("readystatechange", function () {
  25.                     if (this.readyState === 4 && (this.status == 200 || this.status == 200)) {
  26.                         var body = JSON.parse(this.responseText);console.log(body);
  27.  
  28.                         if(body.data != null){
  29.                             id = body.data;
  30.  
  31.                             var divContainer = generateIframElement(position, id, editorialStandards);
  32.  
  33.                             pushAd(id, position);
  34.                             widget_container.appendChild(divContainer);
  35.                             widget_container.dataset.squirrelId = id;
  36.                             widget_container.dataset.loaded = "true";
  37.                             widget_container.dataset.position = position;
  38.                         }
  39.                     }
  40.  
  41.                     if (this.readyState === 4 && this.status == 500) {
  42.                         console.log(this.responseText);
  43.                     }
  44.                 });
  45.  
  46.                 xhr.open("POST", "{{ report_route }}" + "make_model");
  47.                 xhr.send(data);
  48.             }
  49.             else{
  50.                 var divContainer = generateIframElement(position, id, editorialStandards);
  51.  
  52.                 pushAd(id, position);
  53.  
  54.                 widget_container.appendChild(divContainer);
  55.                 widget_container.dataset.loaded = "true";
  56.                 widget_container.dataset.position = position;
  57.             }
  58.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement