1

Below are both my C# and

JavaScript code, I can access this method but I'm not getting the expected output

from "success":

success: function( msg ){ 
    alert( msg.d );  
}

Instead it returns [object object]

Javascript:

             $.ajax({
                type: "POST",
                url: "Home.aspx/UpdateSelectionStatus,
                data: '{id_ver: "' + id + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                success: function(msg){alert(msg.d);},
                failure: function(){ }
            });

C#:

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static string UpdateSelectionStatus(string id_ver){

      return "success" + id_ver;

   }
1
  • please return json value from c# function like this return "{\"success\":\""+id_ver+"\"}"; Commented Jan 10, 2014 at 9:52

3 Answers 3

3

That is the bug:

  alert(msg.d);

just use msg directly:

  success: function (msg) {alert(msg); },

You returned a simple string, not a complex type, so you haven't got any property like "d".

Sign up to request clarification or add additional context in comments.

1 Comment

Have you debugged? How does msg object look like in chrome or firebug debugger? Is it null, or has it got any member? If it returns in success callback, there is no problem with c# code and ajax call. Problem is in callback.
0

Please try below code: it is working at my end.

 var vid = 10;
        $.ajax({
            type: "POST",
            url: "/Home.aspx/UpdateSelectionStatus",
            data: "{id_ver:'" + + vid + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                alert(data.d);
            }
        });

Comments

0
success: function( msg ){ 
    alert( msg.d.toString());  
}

Comments

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.