'I have a SSJS code and AJAX, now how can I put all together?
I have a ssjs code that creates a data extension
var DE = "MyDataExtension"
Platform.Load("core","1.1")
var obj = {
"CustomerKey" : 123,
"Name" : DE,
"Fields" : [
{ "Name" : "Id", "FieldType" : "Number", "IsPrimaryKey" : true, "IsRequired" : true },
{ "Name" : "MyData", "FieldType" : "Text", "MaxLength" : 50 },
{ "Name" : "Active", "FieldType" : "Boolean", "DefaultValue" : true }
]
}
}
}
And I found that to use this ssjs code in onclick function I must use AJAX, so I did it
<script>
function ajax() {
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest;
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
console.log(xmlHttp.responseText);}}
xmlHttp.open('POST','https://...', true);
xmlHttp.send()}
</script>
Now, how should I put all together ?
What i tried ->
<script>
function ajax() {
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest;
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
console.log(xmlHttp.responseText);}}
xmlHttp.open('POST','https://someone.com/LP', true);}
xmlHttp.send()}
</script> <script>
function create(){
var DE = "MyDE"
var obj = {
"CustomerKey" : 123,
"Name" : DE,
"Fields" : [
{ "Name" : "Id", "FieldType" : "Number", "IsPrimaryKey" : true, "IsRequired" : true },
{ "Name" : "MyData", "FieldType" : "Text", "MaxLength" : 50 },
{ "Name" : "Active", "FieldType" : "Boolean", "DefaultValue" : true }
]
}
};
</script>
<button onclick="create();ajax()">
Request
</button>
it's possible ? The code above it's not working, just nothing happens.
My goal is, when a button is clicked, a Data Extension is create, Thanks in advance!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
