当前位置: 代码迷 >> ASP.NET >> ==============ajax怎的得到Web.Services.WebService和返回值
  详细解决方案

==============ajax怎的得到Web.Services.WebService和返回值

热度:4663   发布时间:2013-02-25 00:00:00.0
==============ajax怎样得到Web.Services.WebService和返回值?
1,

diarynew.aspx文件部分代碼:
......
<script   language= "javascript "   type= "text/javascript ">
<!--

function   Button_onclick()
{
    alert(WorkNoteService.Xiao());
}
//   -->
</script>
......
<form   runat= "server "   enctype= "multipart/form-data ">
                <asp:ScriptManager   ID= "ScriptManager1 "   runat= "server ">
                    <Services>
                        <asp:ServiceReference   Path= "WorkNoteService.asmx "   />
                    </Services>
                </asp:ScriptManager>
<input   id= "Button1 "   style= "width:   80px "   type= "button "   value= "添加 "   language= "javascript "   onclick= "Button_onclick() "   />
</form>
......

2,

WorkNoteService.asmx文件部分代码:

<%@   WebService   Language= "C# "   Class= "WorkNoteService "   %>
......
public   partial   class   WorkNoteService   :   System.Web.Services.WebService  
{
......
[WebMethod]
public   string   Xiao()
{
    return   "Finer ";
}
}

執行時,提示“undefined”,我要怎样才能得到返回值?

谢谢!


------解决方案--------------------------------------------------------
如果WebService.Methord(parm1,……)
对应的JAVASCIPT是
function showAlert()
{
WebService.Methord(parm1,……,setValue);
}
function setValue(s)
{
alert(s);
}

但是WebService.Methord没有传入参数怎么写我也已经印象不深了,要不你给WebService添加一个没有用的参数^_^
或者你查看下源文件,看看 " <script src=.axd?d=CSS1Q54nXPsZkV4CgkofReExwY2TTFI0QayaxCmC6WGKSNyF6g6KiugHG5NlLeI6Qs7pxpF86pW8Wy-wi0En6iF5bDexCfge5J2vK-hSjwE1&amp;t=633174158700000000 " pe= "text/javascript "> </script> " 类似的那一串是什么样子的,再根据具体情况改进一下

------解决方案--------------------------------------------------------
所以你的代码要修改成
function showAlert()
{ //下面的函数
WorkNoteService.Xiao(setValue,setValue);
}

function setValue(s)
{
alert(s);
}
  相关解决方案