Dashboards & Visualizations

Python not running on ajax script

japposadas
Explorer

Hi Guys, i'm trying to run an ajax script with a url to a python script. Everytime i tried to run it it seems that it has no error, but it's not working and the script do not continue to the click function. When I tried removing the type: POST in ajax, i got an error which is POST http://localhost:8001/en-US/app/Splunk_ML_Churn/trial2.js 404 (Not Found)

here is my sample code

require([
"jquery",
'splunkjs/mvc',
"splunkjs/mvc/simplexml/ready!"],
function($,mvc){
var tokens = mvc.Components.get("default");
$("#equation_btn_Run").on("click", function (){
console.log("BTN_RUN")
$.ajax({
type: "POST",
url: "trial1.py",
success: function(response) {
console.log("hello");
}
});
});
$('#equation_btn_Save').on("click", function (){ // When button click
console.log("BTN_SAVE")
});
$('#macros_table').on("click", function (){ // When button click
var Equation_name_tok = tokens.get("Equation_name_tok").substr(1).slice(0, -1);
var Equation_value_tok = tokens.get("Equation_value_tok");
$('#Equation_Name').val(Equation_name_tok);
$('#Equation_Value').val(Equation_value_tok);
});
});

please give me some ideas, thanks in advance! Happy Splunking

Tags (1)
0 Karma

micahkemp
Champion

How are you hosting the python script that it can receive POST requests?

0 Karma

japposadas
Explorer

i just put the python script in the local server

0 Karma

micahkemp
Champion

POST is an HTTP action. The code you write, in javascript, will run in the user's browser and attempt to make an HTTP call based on what you've asked it to POST to.

Placing a python script on the server is unlikely to allow it to receive HTTP events.

I think you'll need to take a step back and work to gain an understanding of not only what it is you're looking to accomplish overall, but how the individual components may be used successfully to gain that functionality.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...