src загружается слишком быстро - PullRequest
0 голосов
/ 28 сентября 2018

У меня есть сайт Wix, и я использую форму автозаполнения Карт Google на странице, чтобы получить адрес и передать его в «хранилище wix», которое позволяет переменным перемещаться в «сеансе» пользователей, затем я извлекаю эту переменнуюи поместите его в окно HTML, где у меня есть виджет, который использует src, чтобы дать мне значение того дома, который я буду называть виджетом avm.Моя проблема в том, что виджет avm пытается вычислить стоимость дома слишком быстро, и поэтому код страницы не успевает отправить адрес в HTML и HTML, чтобы передать его виджету.Я понимаю, что wix не является платформой, с которой многие люди связываются с кодом. Я перепробовал почти все, что мог придумать, и все это не работает.

Это код, который я собрал.

<script>
  var q;

  function get_adress() {
    //gets the adress from the page code
    window.onmessage = (event) => {
      q = event.data;
    }
    return window.q;
  }

  var adress = get_adress();
  var rprAvmWidgetOptions = {
    //this is the var that the rpr widget needs 
    Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
    Query: adress,
    CoBrandCode: "btso48",
    ShowRprLinks: false
  }

</script>
<script language="JavaScript">
  //This was my best shot at a script that could hold the loading of the src so that I could by time for my code to get the var.
  function helper() {

    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = '//www.narrpr.com/widgets/avm-widget/widget.ashx/script';
    head.appendChild(script);
  }

</script>

Это обычный код для виджета.Запрос - это то, что мне нужно заменить.

<script>
  var rprAvmWidgetOptions = {
    Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
    Query: "3911 E Douglas Loop, Gilbert, AZ 85234",
    CoBrandCode: "btso48",
    ShowRprLinks: false
  }
</script>
<script src="//www.narrpr.com/widgets/avm-widget/widget.ashx/script">        
</script>

Это мой jquery wix называет его "код страницы"

      // For full API documentation, including code examples, visit                 
http://wix.to/94BuAAs
import wixData from "wix-data"; // activates wix-data
import {session} from 'wix-storage'; // activates wix-storage
$w.onReady(function () {

        let start = session.getItem('1',start);// gets the adress from storage
   setTimeout(
  function() 
  {
  messageSendButton_onClick(start); // waits for html box to load then sneds the adress
  }, 1000);
});
export function messageSendButton_onClick(start) {
  // send message to the HTML Component
  $w('#html1').postMessage(start);
}

1 Ответ

0 голосов
/ 04 октября 2018

Я не очень хорош в объяснении вещей, но предложу подход.

PageCode

 import wixData from "wix-data"; // activates wix-data
 import {session} from 'wix-storage'; // activates wix-storage
 $w.onReady(function () {
    let start = session.getItem('1',start);// gets the adress from storage
    $w("#htmlbox").postMessage({address : start}); }); // send address to wix html box container
 });

Page script

 <script>
   window.onmessage = (event) => {
    if (event.data) {
        let _data = event.data;
        let address = _data.address; //get the address
    }
    var rprAvmWidgetOptions = {
        //this is the var that the rpr widget needs 
        Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
        Query: adress,
        CoBrandCode: "btso48",
        ShowRprLinks: false
    }
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = '//www.narrpr.com/widgets/avm-widget/widget.ashx/script';
    head.appendChild(script);
  }
</script>
...