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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas

    Thursday, June 25, 2026  |  11AM PDT / 2PM EDT  Duration: 1 Hour (Includes live Q&A) Register to ...

Analytics Workspace deprecation

As of Splunk Cloud Platform 10.4.2604 and Splunk Enterprise 10.4, Analytics Workspace is now deprecated. ...

Splunk Developer Day Recap: Building, Publishing, and Growing on the Splunk Platform

Splunk Developer Day brought the Splunk developer community together for a practical look at what it means to ...