Monday, June 3, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  188] [ 2]  / answers: 1 / hits: 23116  / 13 Years ago, fri, june 24, 2011, 12:00:00

I have an asp.net application with a static page method. I'm using the below codes to call the method and get its returned value.



$.ajax({
type: POST,
url: myPage/myMethod,
data: {'parameter':'paramValue'},
contentType: application/json; charset=utf-8,
dataType: json,
success: function(result) {alert(result);}
});


What i got returned is [object Object].



Below is my static method. And I also have EnablePageMethods=true EnablePartialRendering=true in my ScriptManager.



    [WebMethod]
[ScriptMethod]
public static string myMethod(string parameter)
{
return Result;
}


Is there a way for me to get the returned value?


More From » c#

 Answers
33

Try using Chrome developer tools or the firebug plugin from Firfox. Not sure if IE's developer tools lets you inspect the ajax calls?



The resulting string you are looking for is actually within the result object. You need to look at the d variable. I remember reading somewhere why this was, I think it is ASP.NET playing around :|



Try:



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


c#



[WebMethod]
public static string GetTest(string var1)
{
return Result;
}


Hope this helps.


[#91525] Thursday, June 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxh

Total Points: 137
Total Questions: 100
Total Answers: 103

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
maxh questions
Tue, May 18, 21, 00:00, 3 Years ago
Mon, Jan 4, 21, 00:00, 3 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
;