JSON对HTML输出的响应

JSON response to HTML ouput

本文关键字:响应 输出 HTML JSON      更新时间:2023-09-26

我有这个sql数据,虽然我使用了ajax,但我已经得到了响应。我的问题是我得到的响应需要在html上查看,帮助。。

这是我的脚本和HTML代码,请帮我检查一下,谢谢

	function view_info(information) {
		// jConfirm( "<b> Do you want to view the information of this applicant?</b>" + "<br><br>", "Confirm", function(r){
		//     if (r){
		//         newwindow=window.open("<?php echo base_url()?>fg_summary/get_info/" + information,"name","scrollbars=1,height=768,width=950");
		//         if (window.focus) newwindow.focus();
		//     }
		// });
		// alert('test');
		$('#myModal').trigger('click');
	}
	 $("#myModal").click(function(){
		// var _COC_NO     = $("#btn_info").parent().parent().find("td").eq(2).html();
		var _COC_NO = document.getElementById("coc").innerHTML;
		var _DEP_COC_NO   = document.getElementById("depcoc").innerHTML;
			$.ajax({
				type :"POST",
				url  :'<?php echo base_url("fg_summary/get_view"); ?>',
				timeout:    10000, 
				data : {
					COC_NO          : _COC_NO,
					DEP_COC_NO        : _DEP_COC_NO,
				},
				success: function(result){
					var _result = $.parseJSON(result);
					alert(_result);
					  $.each(_result['MSG'], function() {
            				table += '<tr><td>' + this['firstName'] + '</td><td>' + this['lastName'] + '</td></tr>';
				        });
					  	var table = '<table><thead><th>First Name</th><th>Last Name</th></thead><tbody>';
				        table += '</tbody></table>';
				        document.getElementById("myModal").innerHTML = table;
		
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Read and Parse JSON String in jQuery | Example</title>
    <style type="text/css">
    table {
        border: 1px solid #777;
        border-collapse: collapse;
    } 
    table tr th,
    table tr td {
        border: 1px solid #777;
    }
    </style>
</head>
<body>
   
    <div class="modal fade" id="myModal" role="dialog" style="width:1000px">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Information</h4>
        </div>
          <div class="modal-body">
        <div id="datalist">
        </div>
        </div>    
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>

 var jsonobj = eval("(" + result + ")");
  $.each(jsonobj, function(i,val) {
                            table += '<tr><td>' + jsonobj['firstName'] + '</td><td>' + jsonobj['lastName'] + '</td></tr>';
                        });

                        var table = '<table><thead><th>First Name</th><th>Last Name</th></thead><tbody>';
                        table += '</tbody></table>';
                            document.getElementById("myModal").innerHTML = table;