---
title: "EXT的同步请求"
author: "guojian3021886"
date: "2009-08-20T13:50:05Z"
tags: ["Ajax", "EXT", "Firebug", "IE", "json"]
slug: "ext"
draft: false
lastmod: "2009-09-01T13:27:38Z"
id: 453556
url: "https://hchmsguo.iteye.com/blog/453556"
---

今天做DBlock的时候，用ext向后台发送同步请求。代码如下：

```
        var conn = Ext.lib.Ajax.getConnectionObject().conn;
        conn.open("POST", '/group/lock/' + record_id , false);
        conn.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        conn.send('mode=edit');
        var res = Ext.util.JSON.decode(conn.responseText);
        if (res.success == false) {
            Ext.MessageBox.show({
                title : 'エラー',
                msg : res.result,
                minWidth : 260,
                buttons : Ext.MessageBox.OK
            });
        }
```

 结果IE好用，火狐用get方法提交没事，用post提交总出500错误。郁闷。

 

老田网上找到解决方法，在conn.send之前添加一句：

```
conn.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
```

解释贴在下面：

 

一般参数传递通过url后面跟后台也能取到，不过看到send参数也可以发送参数，试验了一下服务器端接受不到发送的参数，在firebug里看到发送的请求post部分是一个串，不太象正常发送的参数。搜索了很久也没有找到方法，后来搜到一篇文章介绍了xmlHttpRequest对象的send方法解释，才知道需要设置一个header属性Content-Type 告诉服务器是form方式发送数据，然后send方法里的参数串才会被服务器解释到。

 

 

其实我的html页也已经配置了上面的属性，不知道为什么没起作用。