I have a test web page for calling a WebApi URL and getting a reply. It works as expected in IE, but none of the other browsers.
Here is the jQuery call I make
$(document).ready(function()
{
jQuery("#cmdCallServiceWithParameter").on("click", function(event)
{
$.ajax({
type: "GET",
url: "http://localhost:64804/api/Voucher/5",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function ()
{
alert("success");
},
error: function (jqXHR, textStatus, errorThrown)
{ // Debug the error!!
alert("error " + textStatus);
alert("error throw " + errorThrown);
alert("incoming Text " + jqXHR.responseText);
}
})
})
});
Here is the code in the voucher controller
// GET api/voucher/5
public string Get(int id)
{
//return JsonConvert.SerializeObject(id, typeof(int), Formatting.Indented, new JsonSerializerSettings());
return "{\"test\":" + id.ToString() + "}";
}
IE returns a Success message, but for the other three browsers I get the three alerts in the error function displayed. The only parameter to be set is the textStatus, which is set to 'error'
When I browse to the URL directly (http://localhost:64804/api/Voucher/5
) on Firefox and Chrome it shows "{\"test\":5}"
in the browser window. IE asks me to download a file named 5.json, and Opera asks me to download a file named 5. Both files just contain the text shown above that appears in the window for Firefox and Chrome
Does anybody have any ideas what the issue could be here, and how I can get it to work in all browsers?