I am trying the new jQuery 1.5 and it broke a few things in my application. I make a call to an action that generates the JSON, but something errors out and causes the script to stop. According to Fiddler and Firebug, the action does return JSON data. I didn't provide the JSON data, but the data is valid according to JSONLint.
Please note that this works as expected in jQuery 1.4.4.
The first thing I noticed was the URL: http://localhost:3219/News/GetAllNewsArchives?callback=jQuery15033185029088076134_1296751219270&_=1296751219672
Script:
// Dropdown box for past articles
$("#article-select").ready(function() {
$.ajaxSetup({ cache: false });
$.getJSON('/News/GetAllNewsArchives', null, function(json) {
var items = "<option value=''>(Select)</option>";
$.each(json, function(i, item) {
items += "<option value='" + item.Id + "'>" + subject + "</option>";
});
$("#article-select").html(items);
});
});
Action:
public ActionResult GetAllNewsArchives()
{
return Json(newsRepository.GetAllNewsArchives(), JsonRequestBehavior.AllowGet);
}
Any ideas of what I am doing wrong?
Okay, I switched to a $.ajax call and I had the same error:
However, I noticed something on the $.ajax() documentation.
I changed my data type from
dataType: "json"
todataType: "text json"
then it worked.Now, I just don't understand why the difference. What does
json
expect that is different?