I'm trying to get a JS script within ebase to test a URL to see of an image is available. Essentially they are photos of colleagues, but not all colleagues have photos. If they have a photo then I'd like to assign the URL to a field value, if they don't have a photo then I'd like to assign a default graphic.
I have tried several versions of code from forums other than ebase (not being able to locate anything via the search facility) but so far have been unable to get the result that I want.
I've tried the following code:
Code: Select all
var urlTest = new XMLHttpRequest();
urlTest.open('GET', 'http://<url>', true);
urlTest.send();
fields.testField.value = urlTest.status;
This returns an error:
Code: Select all
Error: ReferenceError: "XMLHttpReques" is not defined.
The URL is pointing to a file saved on the same server as the ebase installation is running on, so there aren't any issues with trying to get XMLHttpRequests to work X-domain.
I've also tried the following piece of code:
Code: Select all
$.ajax({
url:'http://<url>',
type:'HEAD',
error:function() {
// Contact does not have an available photo, so use the default
fields.CONTACT_PHOTO.value = "NoPhotoAvailable.png";
},
success:function() {
// Contact does have an available photo, so use that
fields.CONTACT_PHOTO.value = fields.USERGUID.value.concat(".jpg");
}
});
This displays the error:
Code: Select all
Error: ReferenceError: "$" is not defined.
Any help would be greatly appreciated.
Thanks in advance
Tom