Does validation scripts allow the use of XMLHttpRequest?
Hi everyone,
My client is developing a "validator" type script and came across the following question:
When a "XMLHttpRequest" object is inserted into the script, the script stops validating on the workitem save event. The validation works on the form, it just does not work at the time of the save event.
The problem happens from the time the line "var xmlhttp = new XMLHttpRequest ();" runs.
Our question for the experts here is: does validation scripts allow the use of XMLHttpRequest?
If necessary I can upload part of the code in which the object is called.
One answer
You have to be very careful with this one - client side validation can use pretty much anything your browser's Javascript engine will understand *AT YOUR OWN RISK*, but the server-side Javascript engine is a lot more limited.
Not only does it not have the full set of functionality, it may also be behind firewalls, and it's also quite an old version of ECMAScript (I have just found out it doesn't support <string>.includes() or <array>.includes()).
I have found I have the most success when I use the extended dojo object jazz.client, but it really depends on what you're doing. The best thing about the jazz.client version of xhr is that it understands the Jazz authentication process.
This is what I do:
dojo.require("jazz.client");
..
(function() {
var jazzClient = jazz.client;
..
var someFunction = function(team, role) {
var xhrArgs = {
url : '<my url>',
headers : {
'Accept' : 'application/xml'
},
handleAs : 'xml'
};
return jazzClient.xhrGet(xhrArgs).then(function(data) {
console.log(data);
return data;
});
};
EDIT: By the way you can use this check to see if the script is executing on the client or the server:
if (typeof dojo.xhrGet === 'undefined') {
console.log('I am on the server'); //this will print in ccm.log
} else {
console.log('I am on the server'); //this will print in the browser Dev console
}