Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8038117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:07:50+00:00 2026-06-05T03:07:50+00:00

Building a PHP script that responds to an Ajax request is as easy as:

  • 0

Building a PHP script that responds to an Ajax request is as easy as:

<?php
  $command = $_POST["command"];
  if ($command == "say_hello") {
    $name = $_POST["name"];
    echo json_encode(array("message" => "Hello, " . $name));
  }
?>

and, at least if you’re using jQuery on the client side, and if you specified a callback function on the original request, the array containing the message will be passed into that callback function.

But with Python it’s not that simple. Or at least I haven’t figured out how to make it that simple. If I just try to “print” a response (paralleling PHP’s “echo” statement above) the client doesn’t get anything back.

Whenever I’ve looked on the internet for how to respond to an Ajax request with Python, the answer always involves using Django or some other web framework.

And I know those things are great, but what is PHP doing that makes using a similar package unnecessary? I would like to be writing my server-side script in Python instead of PHP, but I’d prefer a D.I.Y. approach to using a third-party framework for what should be (right?) a pretty simple task.

Any help? An example of how to do this would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:07:52+00:00Added an answer on June 5, 2026 at 3:07 am

    But with Python it’s not that simple. Or at least I haven’t figured out how to make it that simple. If I just try to “print” a response (paralleling PHP’s “echo” statement above) the client doesn’t get anything back.

    I might have some of the details wrong, but I’ll try to explain why this is the case. Firstly, the PHP you’re talking about is baked directly into the apache webserver. When you do an echo, it outputs the result to the response stream (a TCP connection between the server and client). When you do print in python, what you’re doing is outputting the result to standard out (the command line).

    How most languages work with the web, is that a request comes in to some kind of web server, and that web server executes a program. The program is responsible for returning a stream, which the webserver takes, and streams to the client over the TCP connection.

    I’m assuming that the webserver redirects PHPs standard out to the webservers stream, and that is how PHP is able to use echo to return its result. This is the exception, not the rule.

    So, to use python to serve requests, you need to have a webserver that can execute python in some way. This is traditionally done using CGI. More recently, something like mod_python was used to host the python within apache. Nowadays, wsgi or mod_wsgi is used, which is the standard defined for webservers talking to python.

    You might want to look at something like web.py, which is a minimalist python web framework. This will get you very very close to what you’re trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A php script is building the following (very complicated script that is too long
I'm building a PHP script that feeds JSON data to another script. My script
we are building a PHP script that we need at work to create reports
I have the following php script that is called by jquery ajax function report_range($time,
I'm building a fairly simple PHP script that will need to send some emails
I'm currently PHP building a script that has to update statistics when it finishes
I am building a php script to search and scrape google pages that uses
I'm currently building up a PHP script that will answer HTTP 304 Not Modified
I am working on building a small php/mysql script that will act something like
I'm building a small scale forum script in PHP, and I am having difficulty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.