Lightning
Lightning

Reputation: 1

Accessing results of asmx service from jQuery in ASP.Net 4?

I am having trouble accessing the results returned from my web service. When I monitor it in firebug, I can see that the results being returned are correct, but I'm not sure how to access them. I am getting an error "reference to undefined property data.d"

Here is the code that is calling the service:

<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function () {
$.ajax(
{
contentType: "application/json",
dataType: "json",
type: "POST",
url: "service/myService.asmx/getGameTitles",
data: "{ 'Genre': 'JRPG' }",
complete: Success,
error: Error,
processData: false
})
});

function Success(data, status) {
$("#MainContent_Label1").html(data.d);
}
function Error(request, status, error) {
$("#MainContent_Label1").html(request.statusText);
}
});
</script>

This is what I see when I monitor the call in firebug:

d   ["Game 1", "Game 2"]

0   "Game 1"

1   "Game 2"

and

Success()
data = Object { readyState=4, responseText="{"d":["Game 1","Game 2"]}", status=200, more...}
status = "success"

I'm not sure how to access the results... any tips?

Thanks!!

Upvotes: 0

Views: 186

Answers (1)

Rafay
Rafay

Reputation: 31033

in the sucess handler you can access the results as

function Success(data, status) {
 console.log(data.d[0]);
 console.log(data.d[1]);
}

Upvotes: 1

Related Questions