Heim  >  Artikel  >  Web-Frontend  >  Extjs ajax同步请求时post方式参数发送方式_extjs

Extjs ajax同步请求时post方式参数发送方式_extjs

WBOY
WBOYOriginal
2016-05-16 18:48:311903Durchsuche

ajax同步请求一般下面这样:

复制代码 代码如下:

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方法里的参数串才会被服务器解释到。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn