简体   繁体   English

如何将JSON数组从文本/ JavaScript块传递到精确目标/ Salesforce营销云中的runat = server块?

[英]How do I pass a JSON array from a text/javascript block to a runat=server block in exacttarget/salesforce marketing cloud?

I've got a page with two <script> blocks on it, one running locally, one running on the ExactTarget server: 我的页面上有两个<script>块,一个在本地运行,一个在ExactTarget服务器上运行:

<script type="text/javascript">
var results = localStorage.getItem('results');
var results = JSON.parse(results);
</script>

<script runat=server>
Platform.Load("Core","1");
Write(Stringify(results)); //this returns a 'null' value
var campaignsupdate = DataExtension.Init("0DB9904F-CE05-45E7-8052-    7C6935B4B012");
for(var i=0; i < results.length; i++) {
var rowid = results[i]["ROWID"];
var title = results[i]["title"];
campaignsupdate.Rows.Update({title: title},["ROWID"], [rowid]); 
}
</script>

At the moment, calling 'results' in the 'runat=server' block returns a null value. 目前,在“ runat = server”块中调用“ results”将返回空值。 How do I access the 'results' array in the 'runat=server' block? 如何访问“ runat = server”块中的“ results”数组?

You can't. 你不能 As the Server Side Java Script runs on the server :), it's executed prior to the javascript which is executed on the client machine, so the var 'results' does not exists when you access to it in the SSJS block. 由于服务器端Java脚本在服务器上运行:),因此它是在客户端计算机上执行的javascript之前执行的,因此在SSJS块中访问var'results'时不存在。 As far as I know SSJS can't communicate with javascript so you can't use javascript libraries or code written in a javascript block. 据我所知,SSJS无法与javascript通信,因此您不能使用javascript库或以javascript块编写的代码。 As an alternative, you can pass a value in the GET/POST request and get it in SSJS. 或者,您可以在GET / POST请求中传递一个值,然后在SSJS中获取它。 Have a look at: http://help.marketingcloud.com/en/documentation/exacttarget/content/server_side_javascript/server_side_javascript_syntax_guide/core_library_server_side_javascript_functions/utilities_server_side_javascript_functions/ Request Object and Functions Area 看看: http : //help.marketingcloud.com/zh-CN/documentation/exacttarget/content/server_side_javascript/server_side_javascript_syntax_guide/core_library_server_side_javascript_functions/utilities_server_side_javascript_functions/ 请求对象和功能区域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM