obj说明返回的是对象,你可以alert(JSON.stringify(data));来看看内容,也有可能你js哪儿写错了,直接error了,下面是我写的例子
-------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace Storm.Demos
{
public partial class Hello : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e) {
}
[WebMethod]
public static string SayHello() {
return "hello wolrd!";
}
}
}
如jsp中代码:varxmlhttp;if(window.XMLHttpRequest){xmlhttp=newXMLHttpRequest();}else{xmlhttp=newActiveXObject();}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200){alert(xmlhttp.responseText);//此处获取返回数据}}xmlhttp.open("GET","service/toupdstatus.htm“,true);xmlhttp.send();后台:HttpServletResponseres=ServletActionContext.getResponse();res.setCharacterEncoding("utf-8");try{res.getWriter().write("Hasbeensuccessfullychanged!");}catch(Exceptione){e.printStackTrace();}到此ok,方法返回类型为void,struts.xml内不用写标签