0

I tried to write a programm, which takes javascript input and passes it over to python via ajax. Somehow the programm just runs through without noticing the user input. This is the code I have written so far...

$.when(returnText()).done(function(){
    
})

function returnText(){
    let movie = document.getElementById("movie").value; //get user values
    let year = document.getElementById("year").value; //get user values
    const dict_values = {movie, year} //pass variables into dic
    const s = JSON.stringify(dict_values); //convert into JSON
    console.log(s);
    return $.ajax({
    url:"/test",
    type:"POST",
    contentType: "application/json",
    data: JSON.stringify(s)});
}

I also get a faliure message, that says that the "document.getElementById" equals null.

jabaa
  • 5,844
  • 3
  • 9
  • 30
noooooo
  • 11
  • 1
    You should set it up so that the code begins to run after the input has been committed, which would be the `change` event of the `input`. Your code just runs the code right away. – Scott Marcus Nov 10 '22 at 21:35
  • This demonstrates how to fire the ajax request on input change: https://stackoverflow.com/questions/23712799/post-input-onchange-with-ajax – devlin carnate Nov 10 '22 at 21:50

0 Answers0