I have an ASP.NET Ajax service set up using WebSriptServiceHostFactory in the *.svc file - no web.config configuration. In the contract, I'm starting with two very simple methods:
[OperationContract()]
[WebGet]
string GetPersonalInformationLabel();
[OperationContract()]
[WebGet]
string GetCorporateInformationLabel();
And my jQuery set-up is as follows:
$.ajaxSetup({
type: "POST",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
dataFilter: function(data){
var msg;
if( typeof(JSON) !== 'undefined' &&
typeof(JSON.parse) === 'function')
msg = JSON.parse(data);
else
msg = eval('(' + data + ')');
if(msg.hasOwnProperty('d'))
return msg.d;
else
return msg;
}
});
$("#chkCorporateGift").click(function(){
if($(this).is(":checked")){
$.ajax({
type: "GET",
url: "http://localhost/Services/OG.svc/GetCorporateInformationLabel",
success: function(msg){
$("#lblInformationType").text(msg);
}
});
}
else {
$.ajax({
type: "GET",
url: "http://localhost/Services/OG.svc/GetPersonalInformationLabel",
success: function(msg){
$("#lblInformationType").text(msg);
}
});
}
});
As you can see, ajaxSetup assigns type to be "POST" by default, but I had to override it with "GET" in my two calls below as I was getting "405 Method Not Allowed" probably because the contract uses [WebGet] attribute on both methods
So now that 405 message is gone, I go ahead and call the two methods directly in my browser and they return the expected results. However, nothing is returned when the two methods are called using the jQuery code I've set up above. Any ideas as to what I'm doing wrong?