1

i just tested out a script i made. it is in python. i use ajax, to send a request and try and get the result.

function ajaxFunction(){
    var ajaxRequest;
    var e = document.getElementById("ktype");
    var ktype = e.options[e.selectedIndex].value;
    var acookie = document.getElementById("acookie").value;
alert (ktype +"\n" + acookie);
    try{
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                return false;
            }
        }
    }
    ajaxRequest.onreadystatechange = function(){
        if (ajaxRequest.readyState < 4){
            document.getElementById("resp").innerHTML = "<center><img src='loading.gif' style='max-width:60px; max-height:60px;'></center>";
        }
        if(ajaxRequest.readyState == 4){
            document.getElementById("resp").innerHTML = ajaxRequest.responseText;
        }
    }
ajaxRequest.open("POST", "kindle.py", true);
ajaxRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
ajaxRequest.send("amzcookie=" + acookie + "&ktype=" + ktype);
}

the python script uses CGI. no web framework like django.

when i do this request it just prints the contents of the python file. no code is executed.

2
  • 1
    Can you post the Python code? The JS isn't really relevant. Commented Jul 28, 2012 at 18:41
  • Ditto on posting the Python code. It would also be helpful to have some information on your server setup beyond it being "CGI". Could you provide some information about what server you're running and the relevant portion of its config file? Commented Jul 28, 2012 at 18:47

1 Answer 1

3

You should use JQuery for that ... instead of writing your own Ajax request, it can be written in a line:

$.post('link-to-my-python-script',{data},
          function(answer){
                      // process your request here ..
                  });

You can read more about that here: JqueryPost

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.