Ask coding questions

← Back to all posts
How to retrieving JavaScript variable data using Python?
JBloves27

Hello, the title pretty much explains the question. However, for a more better explanation, I am trying to retrieve a JavaScript variable using Python3, but I keep failing to do so.

If you need the repl link, I will attach the repl link later.

Thanks!

Answered by Highwayman [earned 5 cycles]
View Answer
Voters
JBloves27
Comments
hotnewtop
Highwayman

I that a repl link is definitely needed.

JBloves27

Ok, sorry. This is the repl link @Highwayman

JBloves27

Sorry for pinging you again, but have you looked at it yet? @Highwayman

Highwayman

Sorry, I had school.
Get a client-side js variable to python, I’m assuming for the search request? Why no use a form? Once they submit the form, it would generate a request to your server through the action attribute or whatever and then server side you just handle that request and send back the search results in your response body. Or you could do the same thing with the axios js module if you REALLY want to use just js. Is that what you’re doing?
@JBloves27

JBloves27

Oh, no problem.
Oh, okay. Pretty much, that's what I'm trying to do.

So basically, what you're saying is that I should use a form instead, using the same code, just adding the form tag, and then using Python Flask to retrieve the value, and then send it back to the JavaScript file? @Highwayman

Highwayman

Ah f. I did it again.

It was probably irresponsible of me to answer this question with my schedule :/ sorry bout that.

Yes, that is exactly it.
@JBloves27

JBloves27

No problem!

Okay, thank you so much! @Highwayman

Highwayman

Wow. You are… very fast. @JBloves27

JBloves27

Haha, I just check really often! @Highwayman

Highwayman

Makes sense lol— I guess I was just not expecting it as it’d be the middle of a workday where I am.. 🤷‍♂️ XP
@JBloves27

JBloves27

Lol, same, but I'm checking it during class as well ;) @Highwayman

Highwayman

Lol we are such nerds. F’in great.
@JBloves27

JBloves27

Haha, very great XP @Highwayman

JBloves27

Heya @Highwayman! I tried doing that, however, it returns no value whatsoever. Could you take a look at the code and help me about what's wrong?

Thanks!

Highwayman

Hm… I’m not really sure. I understand the concepts but I don’t do a lot of client-server stuff like this, so I don’t really know why. Maybe it’s because you are sending an html file instead of a json file or whatever? I’m not sure. @JBloves27

JBloves27

Ah, okay. Thanks for helping though! @Highwayman

Highwayman

Happy to. :) @JBloves27