I am trying to use the TeamCity API to retrieve build data in JSON format to show in a real-time display.
The display is a simple JavaScript application, served up as a web-page on a different domain to the TeamCity server. Therefore this has to be handled as a cross origin request (CORS).
My problem is that I cannot find a way of configuring a jQuery ajax request to both handle CORS and ask TeamCity to return a JSON response (rather than an XML response).
I've tried various combinations of settings in my ajax object, with the last version below:
return $.ajax({
url: url,
dataType: "jsonp",
/*accepts: "application/json",*/
type: "GET",
xhrFields: {
withCredentials:true
},
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Accept","application/json");
}
});
The "url" includes the login credentials for TeamCity, to satisfy the Http Authentication.
The response I get is the data I want, but in XML format (details of Request & Response headers below).
So my question is how to configure the ajax request to get JSON back from TeamCity?
Request URL:https://xxxxx/**httpAuth/app/rest/projects**?
callback=jQuery210040475526987574995_1394042043670&_=1394042043671
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:__test=1; TCSESSIONID=F409E3C78BD3649E4DCA846DF5DD97F2;
RememberMe=-116716355^12#-8135087298707329913
Host:builds.quillpinpoint.co.uk
Referer:http://localhost/orqaadmin/BuildMonitor/Index
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/33.0.1750.146 Safari/537.36
Query String Parametersview sourceview URL encoded
callback:jQuery210040475526987574995_1394042043670
_:1394042043671
Response Headersview source
Cache-Control:no-store
Content-Length:1009
Content-Type:application/xml
Date:Wed, 05 Mar 2014 17:55:41 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:no-cache
Server:Microsoft-IIS/7.5
Set-Cookie:RememberMe=-xxxx
X-Powered-By:ARR/2.5
X-Powered-By:ASP.NET