1

AJAX 呼び出しを使用して jsp を呼び出しています。

        var httpRequest = null;
        if (window.XMLHttpRequest) {
            httpRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (!httpRequest) {
            console.error('Cannot create an XML HTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() {
            try {
                if(httpRequest.readyState === 4) {
                    ...
                }
            } catch(e) {
                args.error(e);
            }
        };
        httpRequest.open(args.method, args.path, args.sync);
        httpRequest.setRequestHeader(...);
        var q = '', first = true;
        for(var key in args.params) {
            if(params.hasOwnProperty(key)) {
                if(first) {
                    first = false;
                } else {
                    q += '&';
                }
                q += encodeURIComponent(key) + '=' + encodeURIComponent(args.params[key]);
            }
        }
        httpRequest.send(q);

このリクエストでは、クエリ パラメータを次のように渡します。

{
    from: 'xyz',
    to: 'abc'
}

構築されているクエリも正しいです。

from=xyz&to=abc

ただし、私の JSP では、 を実行するrequest.getParameter("from")と が得られnullます。これを修正するにはどうすればよいですか?

4

1 に答える 1

1

解決策を見つけました:

ヘッダーがありません:httpRequest.setRequestHeader('Content-Type'、'application / x-www-form-urlencoded');

これは、ポストリクエストに必要です。

于 2013-02-04T08:39:06.537 に答える