[英]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.