Hello,
Another way to submit a form is by using Web Service.
For creating a method to which data will be posted from web page, we have to create a form and then create a method in that with name
ws_create.
- Code: Select all
/**
* @properties={typeid:24,uuid:"953E3577-A6FB-45F6-B9F2-0C856795E21E"}
*/
function ws_create(content){
application.output('Data posted : ' + content);
return null;
}
Then in your webpage you have to submit the page using ajax.
- Code: Select all
<!DOCTYPE html><html><head>
</head>
<body>
<form id="myForm">
<label for="name">Company Name:<br></label>
<input name="company_name" value="ABC Company" type="text" /><br><br>
<input type="button" value="Submit" onclick="myFunctionWithWebService();" />
</form>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
<script>
function myFunctionWithWebService() {
var companyValue = document.getElementsByName('company_name')[0].value;
if (companyValue) {
$.ajax({url:'http://localhost:8080/servoy-service/rest_ws/<solution_name>/<form_name>/',
contentType: 'application/json',
type:'POST',
data: JSON.stringify(companyValue),
dataType: 'json',
success: function(data) {
alert('success');
},
error: function(){
alert('fail');
}
});
}
}
</script>
</body>
</html>
Please make sure to add the Jquery file if it not added in the web page.
More information on web service :
Servoy Web Service.
Hope this will help you.
Thanks