为do Struts2转换dojo.xhrGet到dojo / request / xhr

时间:2017-09-12 16:05:11

标签: javascript dojo

我有以下代码正确地将Effect "ContributionEffects.requestManagers" dispatched an invalid action @Effect() requestManagers = this.action$ .ofType(ContributionActions.FETCH_MANAGERS_REQUEST) .map(toPayload) .switchMap(payload => this.contributionsService.requestManagers() .map(res => { const managers = res.json(); const managersContributionsCallArray = []; managers.map(manager => { const data = { reviewId: manager.review_id } managersContributionsCallArray.push(this.contributionsService.requestManagerContributionsPromise(data)); }); Observable.forkJoin(managersContributionsCallArray).subscribe(results => { for (var index = 0; index < managers.length; index++) { managers[index]['contributions'] = results; } return this.contributionActions.fetchManagersReceive([managers]); }); }) .catch(err => this.errorHandler.handleError(err, 'There was an error retrieving your managers', this.contributionActions.fetchManagersFailed()) ) ); 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字段。我在两种情况下都使用了相同的Struts操作。

objectIds

我确实从 <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> 获取了信息。

1 个答案:

答案 0 :(得分: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;
            });