在modal/div中显示ajax响应 - 当响应以网页形式时

问题描述:

我正在做一个ajax调用 - 一种ping操作,以查看用户提供的url是否有效。它可能是GET或POST请求。我想显示get/post请求对用户的响应,所以我使用弹出窗口模式来显示响应。但是,如果响应以网页的形式出现,那么我的原始页面(因为响应网页中的CSS样式)令人不安。 有没有什么办法,所以我可以从我的网页上隔离了这个特定的div分开的,所以风格不被打扰在modal/div中显示ajax响应 - 当响应以网页形式时

以下是用于验证ValidateURLchar变量提供URL(代码片段是休息的API,验证URL并返回响应和响应代码)

function validateURL(char){ 
    var value = char.value; 
    $.ajax({ 
      url: "/FrugalPlatform/validateURL.action", 
      type: "POST", 
      data: { 
       url: value, 
       protocol : protocol, 
      }, 
      success: function(data) { 
       $("#response").html(data.response); 
       $("#modalForResponse").modal(); 
      } 
    }); 
} 

特定响应返回信息的网页

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="//www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 
<meta http-equiv="Content-Language" content="en-us" /> 
<link rel="shortcut icon" 
href="//dnassets-mauganscorp.netdna-ssl.com/images/favicon.ico" /> 
<link rel="search" type="application/opensearchdescription+xml" 
title="Desktop Nexus" href="//www.desktopnexus.com/opensearch.xml"> 
... 
... 

其中包含的数资源链接... 这与我的网页风格搞乱......

snapshot of one such scenario

我是直接试图把HTML响应为div元素,这是令人不安的样式..而是使用即时通讯iframe现在,并修改它的内容动态地

var doc = document.getElementById('responseFrame').contentWindow.document; 
doc.open(); 
doc.write(data.response); 
doc.close(); 

其中responseFrame是IFRAME

的ID