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”,我要怎样才能得到返回值?谢谢!
......
<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”,我要怎样才能得到返回值?谢谢!
解决方案 »
- 如何在下面的基础上修改实现功能?
- 怎样将assembly添加到GAC,新建asp.net网站是像System程序集似的不用添加引用
- 关于拖动层的问题
- 着急,有没有人遇到过这种问题
- gridview怎么自动添加一个序号的列?
- DataGrid中如何邦定某个表?
- datalist中使用<a href="answer.aspx? id=<%# Eval("题目") %>"><%# Eval("题目")%></a>
- 有谁知道在哪里申请收费的域名比较好?期待!!!!!!!
- 想用google的进来
- GridView的一个入门问题求解答
- 新人问个Repeater控件的问题.
- 在ASP.NET里怎样把一个用户POST上来的乱码转换编码
‘WorkNoteService.Finer().value’是空或不是一个物件
public void AddContent(string xxxStr)
{
//写入数据库
}我用上面的方法是可以寫數據到數據裡的,只是有返回值時不行,得不到值!
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FXiao.FinerDb.User;
using FXiao.FinerBusiness;
using System.Collections;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Services.Protocols;
/// <summary>
/// Summary description for WorkNoteService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class WorkNoteService : System.Web.Services.WebService
{ public WorkNoteService () { //Uncomment the following line if using designed components
//InitializeComponent();
}
string UserID,UserDept,UserFactory; [WebMethod]
public string SayHello(String Name) {
return "Hello : " + Name;
}
[WebMethod]
public int AddData(string attachment)
{
int result;
string connstr=ConfigurationManager.ConnectionStrings["connectionEOffice"].ConnectionString;
string sqlAdd="insert into wksAttachment(filename) values('"+attachment+"')";
SqlConnection conn=new SqlConnection(connstr);
SqlCommand cmd=new SqlCommand(sqlAdd,conn);
conn.Open();
result=cmd.ExecuteNonQuery();
conn.Close();
return result;
}
[WebMethod]
//public void AddContent(string deptid,string fid,string subject,string content,string workhoures)
public void AddContent(string paras)
{
UserDetail();
//UploadFile();
string[] contentList=paras.Split('|');
string subject,content,workhoures;
subject="";
content="";
workhoures="";
for(int i=0;i<contentList.Length-1;i++)
{
subject=contentList[0];
content=contentList[1];
workhoures=contentList[2];
}
SqlParameter[] parameters=
{
new SqlParameter("@user_id",SqlDbType.VarChar),
new SqlParameter("@dept_id",SqlDbType.VarChar),
new SqlParameter("@f_id",SqlDbType.VarChar),
new SqlParameter("@subject",SqlDbType.NVarChar,200),
new SqlParameter("@content",SqlDbType.NVarChar,3000),
new SqlParameter("@workhoures",SqlDbType.VarChar),
};
parameters[0].Value=User.Identity.Name;
parameters[1].Value=UserDept;
parameters[2].Value=UserFactory;
parameters[3].Value=subject;
parameters[4].Value=content;
parameters[5].Value=workhoures;
int rows=0;
int result;
Diary myDiary=new Diary("server=10.142.60.169;database=ud_eoffice;uid=xxxx;pwd=yyyy");
myDiary.Add("wks_DataAdd","StoredProcedure",parameters,rows);
/*Response.Write(@"<script>parent.bottomFrame.location.href='diaryshow.aspx'</script>");*/
}
void UserDetail()
{
string sqlstr="";
sqlstr=sqlstr+" select p003_02,p003_03,p003_05,p003_07,p002_02,p002_03 from ut_p003 t";
sqlstr=sqlstr+" join ut_p002 a ";
sqlstr=sqlstr+" on a.p002_02=t.p003_07 ";
sqlstr=sqlstr+" where p003_02='"+User.Identity.Name+"'";
FUser myUser=new FUser("server=10.142.60.169;database=ud_paper;uid=acmesql;pwd=usig");
SqlDataReader dr=myUser.GetUserDetail(sqlstr);
while(dr.Read())
{
UserDept=dr["p003_07"].ToString();
UserFactory=dr["p003_05"].ToString();
}
}
[WebMethod]
public void UploadFile()
{
DateTime nowTime=DateTime.Now;
string savePath=Server.MapPath("\\Attachments\\");
string filename="";
//string fileExt="";
HttpFileCollection files = HttpContext.Current.Request.Files;
for(int i=0;i<files.Count;i++)
{
HttpPostedFile postedFile=files[i];
filename=nowTime.ToString("yyyymmddhhss")+System.IO.Path.GetFileName(postedFile.FileName);
//fileExt=System.IO.Path.GetExtension(postedFile.FileName);
postedFile.SaveAs(savePath+filename);
}
}
[System.Web.Services.WebMethod]
//[System.Web.Script.Services.ScriptMethod]
public string Xiao(string name)
{
return string.Format("Hello {0}!", name);
}
}
以上就是全部代码。
後面這個方法Xiao
前面的AddContent可以
非常感谢!
就是不能得到返回值!http://www.cnblogs.com/dflying/archive/2007/06/05/771490.html
问题就在这个地方
所以你的代码要修改成
function showAlert()
{
WorkNoteService.Xiao(setValue);
}function setValue(s)
{
alert(s);
}
欢迎访问我的BLOG,里面有个原创文章综合讲了ajax调Webservice出现错误的
{
WorkNoteService.Xiao(paras,setValue);
}
对应的JAVASCIPT是
function showAlert()
{
WebService.Methord(parm1,……,setValue);
}
function setValue(s)
{
alert(s);
}但是WebService.Methord没有传入参数怎么写我也已经印象不深了,要不你给WebService添加一个没有用的参数^_^
或者你查看下源文件,看看"<script src=.axd?d=CSS1Q54nXPsZkV4CgkofReExwY2TTFI0QayaxCmC6WGKSNyF6g6KiugHG5NlLeI6Qs7pxpF86pW8Wy-wi0En6iF5bDexCfge5J2vK-hSjwE1&t=633174158700000000" pe="text/javascript"></script>" 类似的那一串是什么样子的,再根据具体情况改进一下
function showAlert()
{ //下面的函数
WorkNoteService.Xiao(setValue,setValue);
}function setValue(s)
{
alert(s);
}
{
alert(result);
}
function showAlert()
{
WorkNoteService.Xiao(paras,setValue());//我这里加上了()
}正确代码:
function showAlert()
{
WorkNoteService.Xiao(paras,setValue);
}
谢谢大家!