0

我已经建立了一个 webapp,在单击按钮时,一个 servlet 被调用,它在上下文路径中的目录中via ajax创建一个。html file

现在,在完成 ajax 调用后,我需要在 div 中打开该 html 文件diffReport

这是我写的脚本

$(document).on('click', '#detect', function() {
var url = document.getElementById("url").value;

$(document).ajaxStart(function() {
      $("#loader").show();
});
$(document).ajaxStop(function() {
    $("#loader").hide();
});

$.ajax({
    url: 'diffReport?url='+url,
    success:function(data){
        $.ajax({
            type : 'GET',
            url : data,
            success : function(msg) {
                $('#diffReport').html(msg);

            }

        });
    }
   });
});

还有我的 div

<div id="diffReport" style="width:45.5%; height: 730px;float:right">
            <p>Diff report will load here....</p>
            <span id="loader">please wait..<br><img alt="loading..." src="resources/images/loader.gif"></span>
</div>

这就是我传递创建的html文件路径的方式

File reportDir = AutoUtils.createDirectory(contextPath+"/resources/htmlreports/");

DiffGenerator.createHtml(someParams,reportDir.getAbsolutePath());  //this creates file with name 'finalDiff.html'

response.getWriter().write(reportDir.getAbsolutePath()+"/finalDiff.html");  //copy the file path in response.

但是之后什么都没有加载ajaxStop。甚至控制台上也没有错误。

请建议。

4

1 回答 1

1

我有一个解决方案。我假设您成功通过 ajax 获取新创建的 html 页面的完整 url。比如我假设你新建的html文件的url是“ http://jsfiddle.net/ ”,这个页面会通过iframe加载到div中。我为此创建了一个演示JSFIDDLE

HTML:

<div id="iframe_div">
</div>

JS:

//url of newly created html file
var file_src = "http://jsfiddle.net/";

$('<iframe>')                      // Creates the element
.attr('src',file_src) // Sets the src attribute 
.attr('height',500)
.attr('width',500)
.appendTo('#iframe_div');
于 2013-10-23T12:04:29.737 回答