gpt4 book ai didi

javascript - 如何将 json 响应显示回网页?

转载 作者:搜寻专家 更新时间:2023-10-31 21:47:44 25 4
gpt4 key购买 nike

我有这样一种情况,当我点击按钮时, Controller 方法被调用。 $http.get 将给我一个 URL 作为响应。当我点击那个 url 时,我得到 Bootstrap 模式(所有模式 html)作为响应。我想将模态响应显示到我拥有的 Bootstrap 模态中。

我该怎么做?

按钮:

<button type="button" class="btn btn-primary" data-target="#pwdConfirm" ng-click="doMethod('ResetPassword',@Model.Id)"><span class="col-sm-12 fa fa-refresh"> Reset Password</span></button>

Controller 代码:

$scope.doMethod = function (method, Id) {
var userId = Id;
var url = "http://" + $window.location.host+ "/User/" +method+"?id=" + userId;
//var url = $window.location.host + "/User/" + method + "?id=" + userId;
$http({
method: 'GET',
url: url
}).success(function (response) {
$scope.successresponse = response;
console.log(response);

}).error(function (response) {
alert(response);
});

来自 console.log 语句的 Controller 响应:

<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Password Reset</h4>
</div>
<div class="modal-body">
<div class="col-md-12">
<img src="/Content/images/greenCheck.png" title="logo" class="imgLogo" />
</div>
<div class="col-md-12">
<p>Password Reset to Default</p>
</div>
</div>
<div class="form-group">
<div class="control-label col-md-4"></div>
<div class="col-md-8">
Password : bforce
</div>
</div>
<div class="modal-footer">
<div class="col-md-6 row">
<a class="page-header fa fa-edit btn btn-warning" href="/User/Index" style="color:white">Activate later</a>
</div>
</div>
</div>

现在我希望此响应在另一个页面中显示为 boostrap 模态。我怎样才能做到这一点 ?

最佳答案

$scope.doMethod = function (method, Id) {
var userId = Id;
var url = "http://" + $window.location.host+ "/User/" +method+"?id=" + userId;
//var url = $window.location.host + "/User/" + method + "?id=" + userId;
$http({
method: 'GET',
url: url
}).success(function (response) {
$scope.successresponse = response;
console.log(response);
var showBadRoleModelInstance = $modal.open({
template: "<div ng-bind-html='htmlContent'></div>",
backdrop: true,
windowClass: 'modal',
controller: modalController,
resolve: {
htmlContent: function () {
return response;
}
}
});
}).error(function (response) {
alert(response);
});



function modalController(htmlContent){
$scope.htmlContent = htmlContent;
}

关于javascript - 如何将 json 响应显示回网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32641650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com