I have an index page split in 2. The left side is a list of documents in a folder. On selecting a document, i make an ajax call to a method within the controller and receive that data which i then display in the right side.
Index view.
<div id="files">
<ul>
@foreach (string file in ViewBag.Files)
{
<li class="fileName">@file</li>
}
</ul>
</div>
<div id="fileContent">
<h3>Choose a log file to view it's content</h3>
</div>
Jquery ajax call
$('.fileName').click(function () {
var fileName = $(this).html();
$(".loader").show();
$.ajax({
type: "POST",
url: '@Url.Content("~/SystemReports/ViewContent")' + "?fileName=" + fileName,
dataType: "text",
data: {},
success: function (data) {
$('#fileContent').html(data);
}
,error: alert('error')
});
});
The first problem I am having is that when the call is made, the alert('error') is displayed and only after that the controller method is accessed. And I Do not know why(if you could help me with this one too, really appreciate).
The second problem I am having is that if the content of the file is very large (for example over : 400.000 chars) the browser freezes while trying to display the received data. I have tried the following on the success parameter :
success: function (data) {
for(var i=0; i<=data.length-4; i++) <- -4 is because of some special char at the end
$('#fileContent').append(data[i])
}
The controller
public PartialViewResult ViewContent(string fileName){
OpenFile(fileName);
return PartialView("PartialViewName");
}
error: alert('error')must beerror: function(){alert('error');}just as for success...