displaying the file data in correct format
Posted
by tazim
on Stack Overflow
See other posts from Stack Overflow
or by tazim
Published on 2010-06-14T05:28:59Z
Indexed on
2010/06/14
5:32 UTC
Read the original article
Hit count: 189
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 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.
© Stack Overflow or respective owner