Javascript JSON响应输出不会在单击事件时更新
我正在尝试使用django构建一个java在线编译器web应用程序。 但每次我通过AJAX调用提交代码时,新代码都会成功发布到view.py,但JSON响应对象仍然是以前的对象Javascript JSON响应输出不会在单击事件时更新,javascript,python,django,ajax,Javascript,Python,Django,Ajax,我正在尝试使用django构建一个java在线编译器web应用程序。 但每次我通过AJAX调用提交代码时,新代码都会成功发布到view.py,但JSON响应对象仍然是以前的对象 def code1(request): response_data={} **codet=request.POST.get("code","")** # getting the code text from Ajax req **output=code(codet)** #sending c
def code1(request):
response_data={}
**codet=request.POST.get("code","")** # getting the code text from Ajax req
**output=code(codet)** #sending code for execution
response_data['result']="Successful" #storing in response
response_data['message']=output
**return HttpResponse(json.dumps(response_data), content_type="application/json")**
def code(code_text):
return execute(code_text)
def execute(code_text):
filename_code=open('Main.java','w+') #creating file
filename_code.flush()
f1 = code_text.split("\n") # splitting code line by line
for i in f1:
filename_code.write(i+"\n") #writing code line by line
filename_code.close() #closing file
time.sleep(2) #giving wait
**compile_java(filename_code)**
#compiling file (Note: I am not using the file passed in compile_java)
**return execute_java(filename_code,input**) #running java file
def compile_java(java_file):
proc = subprocess.Popen('javac Main.java', shell=True)
def execute_java(java_file, stdin):
#java_class,ext = os.path.splitext(java_file)
cmd = ['java ', 'Main']
proc = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
stdout,stderr = proc.communicate(stdin)
stdoutstr= str(stdout,'utf-8')
**
1. return stdoutstr
**
实际上,前面的json响应是针对当前代码(codet)发送的