Skip to main content
Question

JSS Rest API with jQuery


Forum|alt.badge.img+1

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); }, });

4 replies

Forum|alt.badge.img+7
  • Contributor
  • 49 replies
  • January 4, 2016

This may just be a copy/paste issue with your code, but your first line (var jamfAPI) has an opening ' but no closing '.


Forum|alt.badge.img+21
  • Valued Contributor
  • 275 replies
  • January 5, 2016

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?


Forum|alt.badge.img+5
  • New Contributor
  • 3 replies
  • April 27, 2016

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??


Forum|alt.badge.img+5
  • New Contributor
  • 3 replies
  • May 5, 2016

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings