I am trying to use ajax call to get the data from web services whose function has a return value of string in json format.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class MyClass : WebService {
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public Chart RetrieveData(string countries, string startDate, string endDate)
{
Chart c = getData(countries, startDate, endDate);
return c;
}
}
And I am using Ajax like following:
var path = 'pathToXml/file.asmx/RetrieveData?countries=' + countries + '&startDate=' + startDate + '&endDate=' + endDate;
$.ajax({
type: "GET",
url: path,
contentType: 'application/json; charset=utf-8',
success: function (data) {
console.log(data.d);
},
error: function (textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
});
I have read SO posts like this, and this. However, none of these worked