Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX & Python: Response text from python script is an object
    primarykey
    data
    text
    <p><strong>Edited out silly mistake</strong></p> <p>I am using AJAX to access a python script, get some TEXT from the python script &amp; display it on my webpage. </p> <p><strong>My Problem:</strong> is that the response text is this "undefined" when it should be this "bbbb"</p> <p><em>I am confused as to where I am going wrong? Is it my python script is incorrect (not handling AJAX (?requests?) correctly), is it my javascript or is it my WSGI server I made?</em></p> <p>HTML &amp; Javascript:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;script type="text/javascript"&gt; &lt;!-- function post( dest, params ) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { return xmlhttp.responseText; } } xmlhttp.open("POST",dest,true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send( params ); } function onTest() { var response = post( "cgi/aaa.py", "email=blah" ); var output = document.getElementById( "bb" ); output.innerHTML = response; alert( response ); } --&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p id="bb"&gt; abcdef &lt;/p&gt; &lt;a href="javascript:onTest()"&gt;Click it&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>My python script:</p> <pre><code>import cgitb; cgitb.enable() import cgi import os input_data = cgi.FieldStorage() print "bbbb" #print "you said: " + input_data['email'] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload