Does validation scripts allow the use of XMLHttpRequest?
Hi everyone,
My client is developing a "validator" type script and came across the following question:
|
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
}
Comments
Rafael Rodriguez Montes
commented Jul 16 '19, 1:15 p.m.
when I put in a calculation java script it say that there is a problem loading the script
Davyd Norris
commented Jul 16 '19, 7:35 p.m.
Then you have an error in your script
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.