嗨,我已经给出了我的文件上传的完整代码。但在我看来,我只是想返回一个响应并在 UI 上获得警报。但是没有一个返回语句正在工作。如何纠正这个..
EDIT
:我看到服务器端的日志记录语句
<h1>Add Content</h1>
<form method="post" enctype="multipart/form-data" id="contentform" action="/content/savecontent/" >{% csrf_token %}
<b>
<table>
<tr><td><font>*</font>Content Name</td><td> <input type="text" id="cname" name="cname" maxlength="30"/></td></tr>
<tr><td><font>*</font>Description</td><td><input type="text" id="cdescription" name="cdescription" maxlength="30"/> </td></tr>
<tr><td><font>*</font>Type</td><td>
<select id="type" name="type">
<option value="1" selected>Local</option>
<option value="2">Internet</option>
</select>
</td></tr>
<tr><td><font>*</font>Access</td><td>
<select id="access" name="access">
<option value="1" selected>Public</option>
<option value="2">Private</option>
</select>
</td></tr>
<tr><td><font>*</font>Content</td><td id="carea"> </td></tr>
<tr><td></td><td><input type="button" value="Upload" id="addbtn" onclick="ajax_upload('#contentform');"/></td></tr>
</table>
</b>
</form>
<script>
$(document).ready(function() {
$('font').css({'color':'red'})
$("#carea").html('').append('{{form.file_upload}}');
});
function ajax_upload(formid)
{
var form = $(formid);
form.ajaxSubmit({
dataType: 'json',
success: function (data) {
alert("hereeeeeee");
}
} ) ;
}
</script>
视图.py
def savecontent(request):
response_dict={'status':1}
logging.debug(request)
logging.debug("========================================")
return render_to_response('content/confirmation.html', context_instance=RequestContext(request, {'response_dict':response_dict}))
#return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')
#return HttpResponse(simplejson.dumps(response_dict), mimetype='text/html')
#return HttpResponse(simplejson.dumps(response_dict), mimetype='application/json')