Where to write java script for html page in template directory

I have created a template in templates directory the name of the file is program.html

i have button in that file

<button id="download">Download pdf</button>

now i want to send a ajax request to my program.py file which is located at

erpnext/erpnext/schools/program/program.py

what will be the path

in the below script

<script type="text/javascript">

   var xhr = new XMLHttpRequest();
	xhr.open("POST", '/api/method/frappe.utils.print_format.hi');
	xhr.setRequestHeader("X-Frappe-CSRF-Token", frappe.csrf_token);
	xhr.responseType = "arraybuffer";
	xhr.onload = function(success) {
		console.log("e");
	    if (this.status === 200) {
	    	console.log("e");
	        var blob = new Blob([success.currentTarget.response], {type: "application/pdf"});
	        var objectUrl = URL.createObjectURL(blob);

	        //Open report in a new window
	        window.open(objectUrl);
	    }
	};

<script>

please help

You can put your .js file under templates/includes directory and include it in your html with

{% include “your_app_name/templates/includes/program.js” %} and call .py from there

1 Like

@RWEMA_Aimable

thanks very much

and can you help me with the path also

xhr.open(“POST”, ‘/api/method/frappe.utils.print_format.hi’);

Refer to this for an example

2 Likes

oh man thats what i wanted i have been searching for 3 days thanks a lot