如何使用 XMLHttpRequest 中止打破 python 无限循环

问题描述

我正在做一个项目,其中一个按钮通过循环保持处理数小时,我想用 XMLHttpRequest 打破循环,但我没有发现任何有用的东西......让我分享一个简单的例子

  1. Ajax 请求
$.ajax({
    type: 'POST',url: '',data: { csrfmiddlewaretoken: '{{ csrf_token }}',text:text },xhr: function(){
        const xhr = new XMLHttpRequest()
        // I guess solution can be write here
    }
    success: function(data){
        console.log(data.done)
        spin.classList.add('not-visible')
    },error: function(error) {
        console.log(error)
    },})
  1. Views.py
def next_trick(request):

    if request.is_ajax():

        while True:
            print('infinite loop')
            sleep(3)

        return JsonResponse({'done':'hell yeah'})

    return render(request,'uploader/next_trick.html',context)

如何使用 XMLHttpRequest 打破这个 while 循环?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)