Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

javascript - JS calling django function

I have 2 html buttons, one that calls a JS function and one that calls a django request. My JS button who's function is to change the background color of a website:

function change_background(){
document.body.style.backgroundColor = 'green';
}

The JS html button is:

<input type="button" value="java" onclick="change_background()")>

In the Django backend i have a function the that reads and opens a file in a new window:

def opening_function(request):
    file = open('peterexcel.xlsx', 'rb')
    response = FileResponse(file)
 return response

The Django html button is:

<input type="button" value="excel" onclick="window.open('making_the_excel')">

I want to make one button. What I want to do is change it so that when the JS button is pressed it will run the django function. Currently when the django function is ran a blank window pops up and the file is downloaded. I do not want this blank window to pop up. i want to connect the django file reading functionality to the JS button.

Everything I have read says to use AJAX, and that this is not a language but rather a technique. I find the AJAX quite difficult to understand. Can anyone help with this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...