As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
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);
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);
Can I use the above call to a webscript in the alfresco repository from a dashlet?
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>
You can Take url form all web scripts.
And u se the postman which is google crome extension.