复制代码 代码如下:
var conn = ext.lib.ajax.getconnectionobject().conn;
conn.open("post", 'http://localhost:8080/struts2study/treeddget?node=-1',false);
// 这里的conn对象其实就是 xmlhttprequest 对象。
conn.setrequestheader("content-type","application/x-www-form-urlencoded;charset=utf-8");
conn.send("start=" + 0 + "&limit=" + 30 );
var rootjson = conn.responsetext;
一般参数传递通过url后面跟后台也能取到,不过看到send参数也可以发送参数,试验了一下服务器端接受不到发送的参数,在firebug里看到发送的请求post部分是一个串,不太象正常发送的参数。搜索了很久也没有找到方法,后来搜到一篇文章介绍了xmlhttprequest对象的send方法解释,才知道需要设置一个header属性content-type 告诉服务器是form方式发送数据,然后send方法里的参数串才会被服务器解释到。