Good morning, I have this web service:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string ObtenirProvinciaByPoblacio(int CodiProvincia)
{
clsCRUD _ou2 = new clsCRUD();
try
{
_ou2.Connectar();
List<clsProvincies> LlistaProvincies = clsDALProvincies.getList(_ou2, CodiProvincia);
_ou2.Desconnectar();
JavaScriptSerializer jss = new JavaScriptSerializer();
string resultat_Json = jss.Serialize(LlistaProvincies);
return resultat_Json;
}
catch (Exception ex)
{
throw;
}
Which returns a list of objects (In this case there is only one object in the list, but it is not relevant). And in the ajax function I have this:
$.ajax({
url: "/WebServiceCV.asmx/ObtenirProvinciaByPoblacio",
data: "{'CodiProvincia': '" + Codiprovincia + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
$.each(data, function (index, item) {
alert(item);
});
},
error: function (request, status, error) {
alert(request.responseText);
},
failure: function (response) {
alert("arriva al failure");
}
});
The alert shows me the object: [{"Codi":25,"Nom":"LLEIDA"}]
But I can not get the values Codi
and Nom
to work with them. In theory it would be item.Codi
or item.Nom
right?
I have tried several options but I do not get anything.