Javascript code:
...............
...............
var cutid = $(th).attr("data-cutid");
var request = $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Services/Cut.asmx/CheckCuts",
data: "{'cuts':" + JSON.stringify(ListCuts) + ",'idCut':'" + cutid + "'}",
dataType: "json"
}).responseText;
alert(request); // undefined
Function from web service:
[WebMethod]
public string CheckCuts(List<CutM> cuts, Guid idCut)
{
return UtilCut.CheckCuts(cuts, idCut).ToString();
}
The responseText is undefined. Why?
I added async: false to ajax request. Setting async to false means that the statement you are calling has to complete before the next statement in your function can be called.
This code works:
function AjaxCheckCuts(ListCuts,cutid)
{
var request = $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Services/Cut.asmx/CheckCuts",
async: false,
data: "{'cuts':" + JSON.stringify(ListCuts) + ",'idCut':'" + cutid + "'}",
dataType: "json"
}).responseText;
var r = jQuery.parseJSON(request);
r = r.d;
return r;
}