dojo.xhrPost的参数

dojo.xhrPost的参数,post,dojo,get,parameter-passing,Post,Dojo,Get,Parameter Passing,当我使用dojo.xhrGet时,我通过GET dojo.xhrGet ({ url:"MyServerPageURL?Param_A="+"ValueA"+"&Param_2="+"Value2", load: function(data) { //do something }, preventCache: true, sync: true, error: function(err) {

当我使用
dojo.xhrGet
时,我通过
GET

dojo.xhrGet
({
    url:"MyServerPageURL?Param_A="+"ValueA"+"&Param_2="+"Value2",
    load: function(data)
    {
        //do something
    },
    preventCache: true,
    sync: true, 
    error: function(err)
    {
        alert("error="+err); 
    }
});
当我不得不改用
dojo.xhrPost
时,我如何做类似的事情(发送多个参数)?

尝试使用参数。 例如:


除非要发送原始POST字符串,否则不希望使用postData参数。您通常希望使用“content”参数。例如:

dojo.xhrPost({
    url: 'http://whatever...',
    contents: {
        ParamA: 'valueA',
        ParamB: 'valueB'
    },
    load: function(response) {
        // ...
    }
});

注意:使用“内容”也适用于Xhret,无需自己构建查询字符串并附加到URL。

对于xhrPOst,可以提及要发布的表单名称。因此,所有表单元素都会被发布。如果要传递一些附加参数,请在发布的表单中使用隐藏变量。

在服务器上,request.getParameter的值为null。为什么需要dojo.toJson?请您解释一下好吗?postData-这是您希望作为请求正文发送的数据。dojo.xhrPost不做任何处理,它只是作为POST正文传递。在这种情况下需要dojo.toJson,因为postData参数只能是字符串。最好将Accept值和内容类型设置为application/json var xhrags={…,标题:{“Content Type”:“application/json”,“Accept”:“application/json”},}ok。在servlet的
doPost
方法下,当我调用
request.getParameter(“Param_A”)
时,我得到null。我不明白是什么问题。你在服务器端使用什么语言?我对Dojo很陌生。您问题中的代码帮助我了解了xhrGet。非常感谢。
dojo.xhrPost({
    url: 'http://whatever...',
    contents: {
        ParamA: 'valueA',
        ParamB: 'valueB'
    },
    load: function(response) {
        // ...
    }
});