0
ajax呼び出しがうまく動作し、データがビューで処理されるため、成功関数の問題は理解できませんが、成功関数ではデータが追加されませんdivにJsonの応答データがdivに追加されない
私のjqueryのあなたは、私はあなたと仮定応答は、コマンドプロンプトに印刷されたばかりされているとコメントしているので
$(document).ready(function() {
$('#other').click(function() {
var filename = "{{filename}}";
var count = $("#count").val();
$.ajax({
type: 'POST',
url: '/increment_page/',
data: {'name':filename,'count':count,'csrfmiddlewaretoken': '{{ csrf_token }}',},
dataType: 'jsonp',
success: function(data) {
$("#show").html(data.result);
}
});
});
});
テンプレート
<div id="filename">{{filename}}</div>
<input type="text" id ="count" value='1'>
<button id="other">Click
</button>
<div id="show">
{{result|first|slice:"1:"}}
</div>
Views.py
def increment_page(request):
#If the AJAX request
if request.is_ajax() and request.POST:
try:
#Get the filename
name = request.POST['name']
pdf = pyPdf.PdfFileReader(open(name, "rb"))
result=[]
#Extract the file contents
for page in pdf.pages:
result.append(page.extractText())
result = [x for x in result if x != '']
#Get the count
count = int(request.POST['count'])
#Increment the count
#Get the list item at the count(position)p
result=result[count]
my_dict={}
my_dict={'result':result,'count':count}
#print(my_dict)
data =json.dumps(my_dict)
return HttpResponse(data,content_type='application/json')
except:
e = sys.exc_info()
return HttpResponse(e)
else:
raise Http404
#return render(request,'view2.html',{'my_dict':my_dict,'result':result})
これをあなたの 'success'関数に入れて、出力を報告してもらえますか?' console.log(data) ' – Tempux
分かりません。もう一度**すべてのエラー**を隠しています。 。 **これをしないでください**。 tryとexceptを削除し、Djangoにエラーを処理させます。ブラウザの開発ツールに表示されます。 –
jquery angularjs mixのように見えますか、それとも私ですか? – Oluwafemi