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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...