在这里,我只想从我的 Django 视图中的 ajax 调用中获取数据。我正在使用类型 GET ajax 调用来实现我的目的。我不知道如何从中获取数据到我的 Django 视图中。还有一个问题,没有什么是 console.log 没有在控制台上打印任何东西,我是新手,请告诉我如何解决所有这些问题。
<span class="test">yes</span>
ajax 调用
<script>
/*
On focus out on input nickname,
call AJAX get request to check if the nickName
already exists or not.
*/
$(".test").focusout(function (e) {
e.preventDefault();
// get the nickname
var text = $(this).text();
// GET AJAX request
console.log('test hoon')
console.log(text)
$.ajax({
type: 'GET',
url: "{% url 'dashboard' %}",
data: {"text": text},
success: function (response) {
// if not valid user, alert the user
},
error: function (response) {
console.log(response)
}
})
})
</script>
视图.py
class Dashboard(TemplateView):
template_name = "dashboard.html"
def get(self,*args, **kwargs):
amount = self.request.GET.get('text')
print("I m here !",amount)
return render(amount,'dashboard.html',)