Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...