Javascript 使用从服务接收的JSON填充引导模式
我正试图用从服务调用接收到的JSON中的值填充一个模式。对象的简单可理解结构如下所示:Javascript 使用从服务接收的JSON填充引导模式,javascript,jquery,ajax,modal-dialog,bootstrap-modal,Javascript,Jquery,Ajax,Modal Dialog,Bootstrap Modal,我正试图用从服务调用接收到的JSON中的值填充一个模式。对象的简单可理解结构如下所示: var object = [ {Value1: "Val1", Value2: "Val", Value3: [{a:"a",b:"b"}] }] ajax调用如下所示: $.ajax({ type: "GET", url: "myURL", data: id, async: true, dataT
var object = [
{Value1: "Val1",
Value2: "Val",
Value3: [{a:"a",b:"b"}]
}]
ajax调用如下所示:
$.ajax({
type: "GET",
url: "myURL",
data: id,
async: true,
dataType: "json",
contentType: "application/json; charset= UTF-8",
success: function (response) {
//alert("Successfully Inserted");
//alert(JSON.stringify(response));
},
error: function (error) {
console.log(error);
alert("Error!!");
}
});
我验证了响应及其正确性
HTML:
<a href="#openModal">Open Modal</a>
<div id="openModal" class="modalDialog">
<div> <a href="#close" title="Close" class="close">X</a>
<h2>Modal Box</h2>
<input type = "text" id="one" placeholder="Place Val1"/>
<input type = "text" id="two" placeholder="Place Val2"/>
<input type = "text" id="three" placeholder="Place a here"/>
<input type = "text" id="four" placeholder="PLace b here"/>
</div>
</div>
模态盒
在我从服务接收到JSON后,我想在打开模式上填充模式。有人能帮我做这件事吗?
下面是一个例子,它解释了我想要实现的更多目标。在ajax成功后,按如下方式处理响应
success: function (response) {
// add data to modal and open the modal.
$("#openModal").modal('show');
},
我将创建一个函数,为您进行如下填充:
success: function (response) {
PopulateModal(response);
$("#openModal").modal("show");
},
function PopulateModal(data) {
//*** this function targets each input and assigns the correct values
}