I have a very simple OpenRasta app with a Home resource with a single string property of Title (straight from the OpenRasta community doc example).
I've set up both XML and JSON data contracts for the resource like this:
ResourceSpace.Has.ResourcesOfType<Home>()
.AtUri("/home")
.HandledBy<HomeHandler>()
.AsXmlDataContract()
.And.AsJsonDataContract();
From jQuery, I'm able to get the JSON data just fine. However, when I make a jQuery XML Ajax request, I get JSON data back.
My jQuery code looks like this:
$.ajax(
{
url: "/home",
dataType: "xml",
success: function(result) {
$('#xmlSpan').append($(result).find('Title').text());
},
error: function(request, status, ex) {
$('#xmlSpan').append('error: ');
$('#xmlSpan').append(status + ', ');
$('#xmlSpan').append(ex.toString());
}
});
The error information being appended ends up looking like this:
error: parsererror, TypeError: a is null
But here is the interesting part. From Fiddler, my request looks like this:
GET http://127.0.0.1:51041/home HTTP/1.1
Host: 127.0.0.1:51041
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8
Accept: application/xml, text/xml, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: http://ipv4.fiddler:51041/WebForm1.aspx
Cache-Control: max-age=0
...and my response looks like this:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Thu, 04 Mar 2010 18:30:04 GMT
X-AspNet-Version: 2.0.50727
Content-Length: 18
Cache-Control: private
Content-Type: application/json; q=0.5
Connection: Close
{"Title":"Foooo!"}
My request is coming in as "Accept: application/xml" but the response is "application/json" (and the returned data is obviously json).
What am I doing wrong?