03-13-2010 10:30 AM
03-13-2010 01:55 PM
var url = "http://localhost:8080/alfresco/service/somepostwebscript";
var post_field = "foo=1&bar=2";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", post_field.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
03-13-2010 05:22 PM
03-29-2010 06:13 AM
Your problem is that you're using GET request for POST webscript. Use POST http request.
Make yourself a bit of javascript somewhere where you can call this easily for testing:
var url = "http://localhost:8080/alfresco/service/somepostwebscript";
var post_field = "foo=1&bar=2";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", post_field.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
03-29-2010 06:47 AM
Can I use the above call to a webscript in the alfresco repository from a dashlet?
03-29-2010 08:09 AM
03-30-2010 06:34 AM
Can I use the above call to a webscript in the alfresco repository from a dashlet?
Yes, to do that, you should put that as a part of a dashlet javascript (client side .js I think - the one you include in dashlet.get.head.ftl or just include it as inline javascript in dashlet.het.html.ftl).
<webscript>
<shortname>Test Post Webscript</shortname>
<description>Test post webscript</description>
<url>/test-post/test-post-ws</url>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"success": ${success?string},
"message": "<#if errormsg??>${errormsg}</#if>"
}
</#escape>
var logFile = "test_Log.txt";
var folderPath = "Guest Home";
var folderNode = companyhome.childByNamePath(folderPath);
var outputFile = folderNode.childByNamePath(logFile);
if (outputFile == null) {
outputFile = folderNode.createFile(logFile);
}
if (folderNode === null) {
folderNode = companyhome.createFolder(folderPath);
}
try {
outputFile.content +="\n";
var currentdate = new Date().toGMTString();
outputFile.content += currentdate;
outputFile.content +="\n";
model.success = true;
} catch (e) {
outputFile.content +="exception in test : ";
outputFile.content += new Date().toGMTString();
outputFile.content +="\n";
outputFile.content +="exception occurred: ";
outputFile.content += e.message;
outputFile.content +="\n";
// error
model.success = false;
model.errormsg = "Error - " + e.message;
}
<webscript>
<shortname>Test Post WS Dashlet</shortname>
<description>Test post ws dashlet</description>
<family>user-dashlet</family>
<url>/test-post/test-post-dashlet</url>
</webscript>
<div class="dashlet">
<div class="title">Test Post WS Dashlet</div>
<script type="text/javascript">
function testClicked(form) {
var url = "http://localhost:8080/alfresco/service/test-post/test-post-ws";
alert(url);
var post_field = "foo=1&bar=2";
alert(post_field);
http.open("POST", url, true);
alert("after http.open");
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", post_field.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
}
</script>
<form id="test-post" action="" method="post">
<p>
<label>Name</label>
<input type="text" name="name" id="name" /> </p>
<p>
<input type="submit" name="submit" id="new-submit" value="save" />
<input type="button" name="test-post-submit" id="test-post-submit" value="test" onClick="testClicked(this.form)" />
<input type="button" name="cancel" id="new-cancel" value="cancel" />
</p>
</form>
</div>
12-07-2016 08:05 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.