I have a ServiceNow instance running and I'm trying to pull all the users using the JSON Library. I can easily see the JSON list of users if I type in the URL that dumps this data, I'm trying to create a webpage that will take this JSON list and make a list of users out of it. I keep encounter cross domain issues, CORS is not available for me to use therefore I'm trying to dynamically load scripts according to the user's information. This is the code that I'm trying to get working.
function test() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var domain = document.getElementById("domain").value;
var targeturl = "https://" + username + ":" + password + "@"
+ domain + "/sys_user_list.do?JSON&sysparm_action=getRecords";
$.getScript(targeturl + "&callback=dumpData")
function dumpData(data) {
alert(data);
}
}
At this point the script seems to load properly, but it causes a syntax error.
Uncaught SyntaxError: Unexpected token :
How am I supposed to make the getScript call so I can get my JSON Data? Is this even a valid method, I stumbled across when trying to figure this issue out and it seems like its my only option. I've tried YQL but that doesn't work.
EDIT:
I have redone the code to make use of the $.ajax, here is the code
$.ajax({
url: 'https://' + username + ':' + password + "@" + domain + '/sys_user_list.do?JSON&sysparm_action=getRecords&callback=test',
type: "GET",
success: function (data) {
alert("hello");
},
crossDomain: true,
dataType: "jsonp",
jsonpCallback: 'test'
});
function test(data) {
alert("It worked!");
}
I've scoured all the posts relating to this an still can't figure this one out. Anybody have any advice on how to remedy this situation? It still is given the invalid syntax error. Is it just not possible to get this JSON data?
I also have tried YQL to obtain the data but that encounters security issues as well.
Thanks,
Chris