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
Get Updates on the Splunk Community!

Splunk Cloud | Empowering Splunk Administrators with Admin Config Service (ACS)

Greetings, Splunk Cloud Admins and Splunk enthusiasts! The Admin Configuration Service (ACS) team is excited ...

Tech Talk | One Log to Rule Them All

One log to rule them all: how you can centralize your troubleshooting with Splunk logs We know how important ...

Splunk Security Content for Threat Detection & Response, Q1 Roundup

Join Principal Threat Researcher, Michael Haag, as he walks through: An introduction to the Splunk Threat ...