0
<WebMethod()> Public Shared Function micro() As String
    Dim context As HttpContext = HttpContext.Current
    Dim ClientID As String = context.Session(const_SESSION_CLIENT_ID)
    Dim UserID As String = context.Session(const_SESSION_USER_ID)

    If (ClientID Is Nothing OrElse UserID Is Nothing) Then Return SerializeErrorMessage("User not logged in")

    Dim serializer As JavaScriptSerializer = New JavaScriptSerializer()
    serializer.MaxJsonLength = Integer.MaxValue    

    Dim s As String = U.Settings(ClientID, UserID)

    'Return serializer.Serialize(s).ToString()
    Return s.ToString()
End Function

s returns the string that I want but when I get and alert from the client side I'm getting [object Object]

Client side:

datsaa = {};
    $.ajax({
        type: "POST",
        url: "v.aspx/micro",
        data: datsaa,
        contentType: "application/json; charset=utf-8",
        dataType: "text json",
        beforeSend: function (xhr)
        {
            xhr.setRequestHeader("Content-type",
                         "application/json; charset=utf-8");
        },
        success: function (b)
        {
            alert(b);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown)
        {

        }
    });
Amanada Smith
  • 1,893
  • 9
  • 28
  • 42
  • 1
    Have you looked at the JSON returned from the JavaScript call? Try looking, I think WebMethod wraps the returned object and should be access by calling "d.b". – Zachary Jun 29 '12 at 17:39
  • You're receiving a json Object back. Set it to a variable and you should be able to access the values of it. Easiest thing would be in your success: `function(b){ var x = b; console.log(x); }` this should show your object and you can access its properties from there – jeschafe Jun 29 '12 at 17:40
  • Try returning list instead of string and it will work. – Ashwin Singh Jun 29 '12 at 17:43
  • I just did a alert($.parseJSON(b.d)) and I got a number value so looks like client side needs parasing? – Amanada Smith Jun 29 '12 at 17:46
  • dataType: "text json", ?? Shouldnt be dataType: "json", – Suave Nti Jun 29 '12 at 17:47

1 Answers1

1

You will get string in b.d , for details read this

success: function (b)
{
      alert(b.d);
}
Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204