简体   繁体   English

在以POST(而不是GET)发送请求后,如何将对象作为html页面插入到来自后端的html元素中?

[英]How to insert object as html page into html element which is coming from back-end after sending request as POST (and not GET)?

I'm sending parameters from frontend and receiving a html object as response from backend. 我正在从前端发送参数,并从后端接收html对象作为响应。 My request parameters are large text fragments which I must send as POST request parameters, or request object and I cannot send them as url path parameters with GET method for some reasons (like too large text, security and secrecy). 我的请求参数是大文本片段,我必须将其作为POST请求参数或请求对象发送,由于某些原因(例如文本太大,安全性和机密性),我无法使用GET方法将它们作为url路径参数发送。 Say I have in Html: 假设我在HTML中:

<button ng-click=" myFunction (myParam1, myParam2)">Send </button>
 <div id="myElement"></div>

in script: 在脚本中:

function (myParam1, myParam2){
    var myParams={' myParam1':  myParam1, ' myParam2': myParam2};
    return $http({
        method: 'POST',
        url: "/postparameters",
        data: myParams
    }).then(function(data) {
        document.getElementById("myElement").innerHTML = data;           
    })
};

In my backend (java Spring) I process parameters and return String object that is html text. 在后端(java Spring)中,我处理参数并返回html文本的String对象。 There is no problem with backend (it return proper html text and I tested and it). 后端没有问题(它返回正确的html文本,并且我对其进行了测试)。 Problem is how to receive html object in my html element? 问题是如何在我的html元素中接收html对象? When I try it I'm getting like [object Object]. 当我尝试它时,我会变得像[object Object]。

As an option (that could receive html object in html element) but I cannot use here, in this case: If I use ng-include=" 'url' " (and url from my backend) then I could only include parameters in url as path parameters, I could only use GET method. 作为一种选择(可以在html元素中接收html对象),但在这种情况下,我不能在这里使用:如果我使用ng-include =“'url'”(以及后端的url),则只能在url中包含参数作为路径参数,我只能使用GET方法。 But in my case I need to use POST. 但就我而言,我需要使用POST。 Can I use ng-include with POST or use something else that can work with POST and avoiding parameters in url path? 我可以在POST中使用ng-include还是可以在POST中使用其他东西并避免在URL路径中使用参数?

尝试这个

document.getElementById("myElement").innerHTML = data.data;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将弹出窗口绑定到作为来自后端 API 的 GET 请求响应进入的 FeatureCollection 的每个元素? - How do I bind a pop-up to each element of a FeatureCollection coming in as a GET request response from back-end API? 如何在后端捕获 POST 请求? - How to catch POST request on back-end? 如果由于用户不存在而导致对API的后端GET请求失败,如何显示404页面? 前端和后端分离 - How to display 404 page if a back-end GET request to an API fails because user doesn't exists? Separated front-end and back-end 如何创建编辑/创建 HTML 页面的 PHP 后端 - How to Create a PHP back-end that edits/creates HTML pages 在JavaScript / HTML前端和PHP / MySQL后端之间发送或链接文件 - Sending or linking files between a JavaScript/HTML front-end and a PHP/MySQL back-end 如何从反应前端向节点后端发出发布请求? 获得 404 - How do I make a post request from a react front-end to a node back-end? Getting 404 从原始页面发送POST请求后,发送新的HTML页面并对其进行GET请求 - Send new HTML page and make GET request to it after POST request from original page 我如何在 Vue.js 中将带有一些数组对象值的 Post 请求发送到我的后端 - How do i send Post request with some values of array object to my Back-end in Vue.js 无法从 React 前端向 Node.js 后端发送 POST 请求 - Can't send POST request from React front-end to Node.js back-end 从前端javascript向后端node.js发送POST请求 - Send POST request from front-end javascript to back-end node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM