转换dojo. xhr转到用于Struts2的dojo/request/xhr

whhtz7ly  于 2022-12-16  发布在  Dojo
关注(0)|答案(1)|浏览(188)

我有下面的代码,它将codeobjectIds正确地传递给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;
                });

            };
        };

在新代码中,数据没有传递到codeobjectIds字段,我在这两种情况下使用了相同的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那里得到了信息。

bvuwiixz

bvuwiixz1#

您需要使用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;
            });

相关问题