2

I have a small problem, with my webservice call. I've debugged it, and the webservice gets called, with the correct value and it also returns the correct value. However, my alert (in the completed function)says: 'undefined'. What am I doing wrong? Here's my function:

function GetServiceValue() {
var Parameter = "{contextKey: '" + $('#<%= ProjectNumText.ClientID %>').val() + "'}";
alert('Para: ' + Parameter);
$.ajax({
    type: 'Post',
    url: 'DynamicPopulateService.asmx/GetProjectName',
    data: Parameter,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
        AjaxSucceeded(msg);
        },
    error: AjaxFailed
});}

And here is the completed function:

function AjaxSucceeded(data)
{
alert(data.responseText);
}

1 Answer 1

3

It looks like you're using ASP.NET. ASP.NET script services return the JSON response under a wrapper object called simply "d". Try this:

function AjaxSucceeded(data)
{
    alert(data.d.responseText);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent, it worked! Except, I removed responseText. So alert(data.d)
All properties of the object returned by the web serice will be available under the data.d wrapper object. If the object returned from your web service doesn't have a responseText property, then neither will data.d. It's very easy to see what's happening if you use the JSON tab in firebug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.