jQuery的AJAX调用的返回值 [英] jquery ajax call return value
问题描述
我有一个静态页面方法的asp.net应用程序。我使用的是下面的codeS调用该方法,并获取其返回值。
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].
下面是我的静态方法。而且我也有我的ScriptManager的EnablePageMethods =真的EnablePartialRendering =真。
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?
感谢
编辑:很抱歉,网上找来当我在提交问题断开。 IE浏览器保存的问题的一部分。
So sorry, internet got disconnected while i was submitting the question. IE saved part of the question.
推荐答案
尝试使用Chrome浏览器的开发者工具或Firfox的萤火虫插件。不知道如果IE的开发工具可以让你检查的AJAX调用?
Try using Chrome developer tools or the firebug plugin from Firfox. Not sure if IE's developer tools lets you inspect the ajax calls?
您正在寻找的结果字符串实际上是结果对象之内。你需要看看D变量。我记得读书的地方这是为什么,我觉得这是ASP.NET玩了:|
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 :|
尝试:
success: function(data) {alert(data.d);}
C#
[WebMethod]
public static string GetTest(string var1)
{
return "Result";
}
希望这有助于。
Hope this helps.
这篇关于jQuery的AJAX调用的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!