How to pass dialog property value to AJAX request in sightly JAVA Script USE API.?

1.5k views Asked by At

Am using server-side JavaScript USE API to read the dialog properties like below

use(function () {
var myproperty = properties.get("renderpagetype");
return { callajaxvariable: myproperty,
};
});

How to pass/get this dialog property value and call an AJAX request in sightly.? (i.e. i need the dialog value which has been retrieved by JS USE API into a page level Java script usage).

1

There are 1 answers

1
Ahmed Musallam On BEST ANSWER

Here is a very simple example of what you are trying to achieve based on your question:

simple.js

use(function () {
  var myproperty = properties.get("renderpagetype");
  return {callajaxvariable: myproperty};
});

simple.html

// simple.html
<script data-sly-use.simple="simple.js">

  /* assuming you use jquery */
  $.ajax({
    method: "POST",
    url: "/path/to/backend/servlet",
    someParam: "${simple.callajaxvariable @ context='scriptString'}"
  })
</script>