+2
Є відповідь

Executing Warewolf service in javascript

Henry Jones 10 років тому в Server / Execution оновлено Gandalf 10 років тому 3
Hi,

I saw the example for executing a warewolf service using Javascript in the examples folder. However i tried doing it using jQuery as so

<script type="text/javascript">
function execution() {
var wareWolfUrl = "http://localhost:3142/services/Hello World.json

$.ajax({
type: "GET",
url: wareWolfUrl,
cache: false,

success: function (response) {
console.log(response);
},
error: function (errorThrown) {
console.log(errorThrown);
},
complete: function (e) {
console.log(e);
}
});
}
</script>

i am getting the following error:

XMLHttpRequest cannot load http://localhost:3142/services/Hello%20World.json? No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:23128' is therefore not allowed a... response had HTTP status code 401.

Am i doing something wrong or is the way in the sample the only way that the service can be executed.

Thanks
web execution
+2
Under review
Hi Henry,

It is possible to perform this type of request with a few adjustments to your request. You need to change your request as follows:

<script type="text/javascript">
function execution() {
var wareWolfUrl = "http://localhost:3142/services/Hello World.json


$.ajax({
type: "GET",
url: wareWolfUrl,
cache: false,
xhrFields: {
withCredentials: true
},

success: function (response) {
console.log(response);
},
error: function (errorThrown) {
console.log(errorThrown);
},
complete: function (e) {
console.log(e);
}
});
}
</script>

As jQuery just wraps a XMLHttpRequest object anyway we just need to set the option for credentials which is the bold in colour part of the request. This should make the request execute correctly now.

Please let us know if you have any other trouble or suggestions.

Thanks for the feedback
-Genie