2016-08-21 80 views
0

客户端具有以下网页显示HTML网页,当我点击保存按钮我的服务器创建新的HTML页面作为响应,但相同的是没有得到浏览器中显示。请建议如何使用ajax解决此问题。如何在AJAX的jQuery的响应后使用方法

<div class='form-group'> 
    <div style='background-color:#EFEFF4'> 
    <div class='buttoncolumn' style='padding-top: 90px;padding-bottom: 5px; width:100%; background-color:#EFEFF4;'> 
     <button id='disableGo' class='buttoncolumn' type='submit' style=' background-color:#007AFF; filter: alpha(opacity=40); -moz-opacity: 0.4;opacity: 0.4;bottom:4%; margin-left:8%;position:absolute;border:none !important;' disabled> Save </button> 
     <button id='go' class='buttoncolumn' type='submit' style=' display:none;background-color:#007AFF;bottom:4%; margin-left:8%;position:absolute;border:none !important;'> Save </button> 
    </div> 
    </div> 
</div> 

<script type='text/javascript'> 
    $(document).ready(function() { 
    $('#TACForm').validate({ 
     rules: {streetnum: 'required',postalCode: 'required',}, 
     highlight: function(element) { 
     $(element).closest('.form-group').addClass('has-error'); 
     }, 
     unhighlight: function(element) { 
     $(element).closest('.form-group').removeClass('has-error'); 
     }, 
     errorElement: 'span', 
     errorClass: 'help-block', 
     errorPlacement: function(error, element) { 
     var found = $(element).closest('.checkbox'); 
     if(found.length) { 
      error.insertAfter(found); 
     } else { 
      error.insertAfter(element); 
     } 
     }, 
     submitHandler: function(form) { 
     var paramsEncoded = $('form').serialize();  
     notificationRequest(paramsEncoded); 
     } 
    }); 
    function notificationRequest(params) 
    { 
     $.ajax({ type: 'post', 
       url: '/ium-tac/', 
       data: params, contentType: 'application/x-www-form-urlencoded;charset=UTF-8', 
       success: function(response) { 
       registered(true); 
       console.log(response); 
       }, 
       error: function(request, errorType, errorMessage) { 
       console.log('Error ' + errorType + ' : ' + errorMessage); 
       } 
      }); 
    } 
</script> 
+0

你想,一个新的窗口将在响应HTML打开?一个'iframe'?替换当前页面的HTML? –

+0

我希望它会用新的html网页替换当前页面中的内容。 –

+0

这可能是这篇文章的副本:http://stackoverflow.com/questions/483745/replace-html-page-with-contents-retrieved-via-ajax –

回答

0

基本上可以代替你想使用.html方法在jQuery中的任何元素的HTML内容。事情是这样的:

function loadNewContent() { 
 
    // Assowme that this content fot from the $.ajax method 
 
    var newPageContent = 'New content'; 
 

 
    $('div').html(newPageContent); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div>Old content</div> 
 
<button onclick="loadNewContent()">Load content</button>

但我不认为这是很好的替代整个 HTML内容。只需加载相关的html并将其附加到特定的部分即可。