4 Replies - 738 Views - Last Post: 05 November 2012 - 02:56 PM Rate Topic: -----

#1 nycnorb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 12

Can someone connect the dots for me? Javascript <-> Python via

Posted 04 November 2012 - 08:39 PM

Hi all,

I'm looking for a way for javascript to interact with python (which runs a server side process). Essentially I want to send a command with a the web, and have python execute certain code. but I'm lost as how I should get python to view/process and send back commands.

I have an apache server up and python 2.7.

Thanks in advance!


Read more at http://www.codingfor...WAI8jkPOITlC.99

Is This A Good Question/Topic? 0
  • +

Replies To: Can someone connect the dots for me? Javascript <-> Python via

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4307
  • View blog
  • Posts: 12,088
  • Joined: 18-April 07

Re: Can someone connect the dots for me? Javascript <-> Python via

Posted 04 November 2012 - 08:45 PM

Javascript is client side... Python renders javascript. Javascript can send parameters as part of request to a Python script on a web server. This is how the two communicate.

1) Javascript sends a request... somedomain.com/script?var=1&var2=2
2) Web server runs python script to handle the request, seeing "var" and "var2" as variables being passed in the request.
3) Python works with variables and prints out some javascript to the client
4) Client gets back javascript in the response and runs javascript.
5) Javascript can make another request

Rinse and repeat.

This is the same method used to run other server-side languages like PHP or ASP.NET in conjunction with Javascript.

:)
Was This Post Helpful? 1
  • +
  • -

#3 nycnorb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 12

Re: Can someone connect the dots for me? Javascript <-> Python via

Posted 04 November 2012 - 09:28 PM

Thanks for the response Martyr2. I guess my confusion in all this is the "Web server runs python script to handle the request" portion.

So I have to install a python WSGI? But wouldn't this be redundant as I'm running an apache webserver already?

So lost... :whistling:
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: Can someone connect the dots for me? Javascript <-> Python via

Posted 05 November 2012 - 04:33 AM

Quote

So I have to install a python WSGI? But wouldn't this be redundant as I'm running an apache webserver already?


Web Server Gateway Interface:

Quote

The Web Server Gateway Interface (WSGI /ˈwɪzˌɡiː/) defines a simple and universal interface between web servers and web applications or frameworks for the Python programming language.


Web servers at their core don't speak any language other than the HTTP protocol. To interact with other languages, like Python, PHP, C++, C#, some sort of plugin/interface is required. With Python this is WSGI. With PHP (and Apache) this is often the Apache module mod_php.
Was This Post Helpful? 1
  • +
  • -

#5 nycnorb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-November 12

Re: Can someone connect the dots for me? Javascript <-> Python via

Posted 05 November 2012 - 02:56 PM

Now I get it. Thanks fellas!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1