Posted on 12-30-2015 05:47 AM
I'm trying to hit the rest API from a website using jQuery. Since I ran into a cross site scripting issue, I'm using jsonp as the datatype. Although I'm seeing a 200 status getting returned, there seems to be an issue with reading the data. I tried changing the contentType around to several other options, but they don't seem to work.
Does anyone know a better javascript method for this or have any idea on what I'm doing wrong?
Error message
SyntaxError: expected expression, got '< <?xml version="1.0"" etc
Here's the jquery code snippet.
var jamfAPI = 'https://ourjamfurl /JSSResource/computers/match/useridhere;'
function setHeader(xhr) {
xhr.setRequestHeader('username', 'theusername'); xhr.setRequestHeader('password', 'thepassword'); } $.ajax({
url: jamfAPI,
type: "POST",
dataType: "jsonp",
processData: false,
contentType: "application/json",
beforeSend: setHeader,
success: function () {
alert('success');
},
error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(xhr.responseText); }, });
Posted on 01-04-2016 08:18 AM
This may just be a copy/paste issue with your code, but your first line (var jamfAPI) has an opening ' but no closing '.
Posted on 01-05-2016 11:34 AM
I've had problems where it unpredictably returns XML or JSON if you don't explicitly ask for one or the other. It looks like you are though, but it's ignoring you and sending XML anyway, can you change datatype to "xml" instead?
Posted on 04-27-2016 01:22 PM
Did you ever get this issue resolved?
I am having the exact same problem - the api only returns xml even though json is explicitly called for in the ajax request.
Curiously, the api does return json when queried in a REST client, just not to an ajax request??
Posted on 05-05-2016 04:28 AM
As of 5/22/2016 per jss tech support:
"We do support ajax queries, and that right now there is a bug with headers in the JSS that's causing it to only return XML."
this bug seems to only apply to javascript ajax calls.