Hello,
Can I call third party rest service in my javascript? I tried to wrote a piece of code like this:
Appery.testCallRest = Appery.createClass(null, {
Code: Select all
init: function(requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},
process: function(settings) {
if (this.__requestOptions.echo) {
settings.success(this.__requestOptions.echo);
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = OK
// ...our code here...
settings.success(XHRResponse);
settings.complete('success');
}
else
{
alert("Problem retrieving XML data");
}
}
};
xmlhttp.open("post","[url=http://mydomain.com/rest/service_name",true]http://mydomain.com/rest/service_name...[/url]);
xmlhttp.send(null);
}
} });
when I define a service using this code, at run-time system report error:
XMLHttpRequest cannot load http://mydomain.com/rest/service_name. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://appery.io' is therefore not allowed access.
I knew I should define a rest service and point the url to external rest url, however the outside service need me to give a multipart-form data, I don't know how to give that data when defining rest service in appery.io.