html element code help needed

Here is my page code

import wixData from ‘wix-data’;
import {session} from ‘wix-storage’;

$w.onReady(function () {
//TODO: write your page related code here…

let subCat = session.getItem(“cat”).toString();

wixData.query("DRH_AdTitle") 
.eq("pageSubCat", subCat) 
.find() 
.then( (results) => { 
	let item = results.items; 
	let pageAd = item.pageAd; 
	let pageTitle = item.pageTitle; 
	
	$w("#html1").postMessage(pageAd); 
	$w("#text15") === pageTitle; 

} );

});

Here is whats in my html component…

<!doctype html>

  1. I’m seeing this error in developer tools as I was seeing in console before I removed the catch… Is there a way to fix this?
  • Wix code SDK error: The message parameter that is passed to the postMessage method cannot be set to the value . It must be of type object,string… There apparently is a validation issue somewhere in this file validation.es6. It doesn’t like that I am using a variable to identify the message text in my page code here $w(“#html1”).postMessage(pageAd);

The error that I was seeing was not related to the issue with the html being applied to the html element. so I removed it from my previous comments.

Hi dollarrockheaven, I am wondering how you were able to resolve “Wix code SDK error: The message parameter that is passed to the postMessage method cannot be set to the value …”

I am coming across this in a few places – including an example put out by the Wix team. For e.g: https://www.wix.com/code/home/example/Chart (this example no longer works on the wix site and when you open it in an editor to figure out what’s going on – I see the same Wix code SDK error.

Would be great to hear your inputs …

Hi guys,

I checked out the Chart example and you’re correct, for some reason it’s broken. A ticket has been opened for this to be fixed.

Meanwhile, an easy workaround is to just send the data as a string. For example:

  • create a string from an array: array.join(‘,’)

  • split the string up into an array: array.split(‘,’)
    I used commas as delimiters between the values, but you can use whatever character you find most suitable.

I tested the Chart example using this technique and it works fine.

Have fun,

Yisrael

Thanks Yisrael – looking forward to long-term solution from Wix.

Another workaround for complex objects that some may want to pass using postmessage:

  1. Use JSON.stringify on the object to be sent via postmessage (hat tip to Andreas Kviby for this suggestion)
  2. Correspondingly use the JSON.parse in the window.onmessage function to rebuild the object

Cheers, Teji

Hello Yisrael,
Since you opened a ticket for this, will the array.join and array.split functionality stop working once the fix is made?
Want to point out exactly when this happened .Last Friday 02/09/2018 somewhere around noon I was trying to work on my site and Wix wouldnt let me save because of scheduled maintenance. Anyway, things saved fine after the scheduled maintenance but charts that used to work stopped working with precisely this error message. I thought this might be useful to know which build broke our live websites

Please let us know when charts are back.
Cheers,Vidya

Hi Vidya,

Don’t worry, join and split are native Javascript array functions and won’t go away. Also, the HtmlComponent will continue to support passing strings - it will just become more robust and will suppor a wider range of objects being passed.

I’ll pass along your report regarding when things stopped working.

Thanks,

Yisrael