JS代码:
function submitName(){
var name = $("#nameId").val();
$.post("/blog/test/",{name:name},function(data){
$("#outId").text(data)
}).error(function () {
alert("Error");
});
}
HTML部分:
<div>
<form action="/blog/" method="POST" id="formId">
<input type="text" name="name" id="nameId"/>
<input type="button" onclick="submitName()" value="提交"/>
</form>
</div>
<div id='upDiv' name='upDiv'>
Name = <font color="red" id="outId">NULL</font>
</div>
view部分:
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
@csrf_exempt
def tttt(request):
response=HttpResponse()
content = request.POST.get('name')
print(content)
response.write(content)
return response