【问题标题】:Converting dojo.xhrGet to dojo/request/xhr for Struts2将 dojo.xhrGet 转换为 Struts2 的 dojo/request/xhr
【发布时间】:2017-09-12 16:05:11
【问题描述】:

我有以下代码正确地将code 和objectIds 传递给trailDesignations.action。

            UpdateTrailDesignationGridClass = function(){
            this.updateTrailDesignationGrid = function(){

                var value1 = 35;
                var xhrArgs = {
                        url: "/trails/trailDesignations.action",
                        handleAs: "text",
                        preventCache: true,
                        content: {
                            code: value1,
                            objectIds: "35.36"
                        },
                        load: function(data){
                            featureResultsContent.innerHTML = data;
                        },
                        error: function(error){
                            featureResultsContent.innerHTML = "An unexpected error occurred: " + error;
                        }
                };

                // Call the asynchronous xhrGet
                var deferred = dojo.xhrGet(xhrArgs);

            };
        };

但由于 xhrGet 已被弃用,我正在尝试使用以下代码对 dojo/request/xhr 做同样的事情。

        UpdateTrailDesignationGridClass = function(){
            this.updateTrailDesignationGrid = function(){
                var value1 = 35;
                xhr("/trails/trailDesignations.action",{
                    data:{
                        code: value1,
                        objectIds: "35.36"
                    },
                    preventCache: true

                }).then(function(data){
                    featureResultsContent.innerHTML = data;
                },function(err){
                    featureResultsContent.innerHTML = "An unexpected error occurred: " + error;
                });

            };
        };

使用新代码,数据不会传递到code 和objectIds 字段。我在这两种情况下都使用了相同的 Struts 动作。

        <action name="trailDesignations" class="gov.mo.dnr.tis.map.TrailDesignations">
        <result name="success" type="stream">
            <param name="contentType">text/html</param>
            <param name="inputName">inputStream</param>
        </result>
    </action>   

我确实收到了来自trailDesignations.action 的信息。

【问题讨论】:

  • 在您的浏览器developer tools 中查看以前和此 http post 原始数据之间的区别。
  • Dojo 本身在 Struts2 中已被弃用;)
  • 用什么代替?我没有使用插件。
  • 你应该在你的评论中写上 {AtSign}RomanC 来提醒他。
  • @RomanC 它被什么替换了?我没有使用插件。

标签: javascript dojo


【解决方案1】:

您需要使用 query :{} 来传递有效负载...您可以找到文档@http://dojotoolkit.org/reference-guide/1.10/dojo/request/xhr.html 对于发布请求数据:可以使用 {}。

xhr("/trails/trailDesignations.action",{
                query:{
                    code: value1,
                    objectIds: "35.36"
                },
                preventCache: true

            }).then(function(data){
                featureResultsContent.innerHTML = data;
            },function(err){
                featureResultsContent.innerHTML = "An unexpected error occurred: " + error;
            });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    相关资源
    最近更新 更多