hi,
In views.py
def showfiledata(request):
with open("/home/tazim/webexample/tmp.txt") as f:
read_data = f.read()
f.closed
return_dict = {'filedata':read_data}
json = simplejson.dumps(return_dict)
return HttpResponse(json,mimetype="application/json")
In the template:
<html>
<head>
<script type="text/javascript" src="/jquerycall/"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("button").click(function()
{
$.ajax({
type:"POST",
url:"/showfiledata/",
datatype:"json",
success:function(data)
{
var s = data.filedata;
$("#someid").html(s);
}
});
});
});
</script>
</head>
<body>
<form method="post">
<button type="button">Click Me< /button>
<div id="someid">< /div>
</form>
</body>
</html>
I am suppose to display file line by line . But, right now the lines get displayed withoout any linebreaks.