0

I am exploring web development using angularJs and python When i try to make an ajax call to execute a script in python i receive the whole text inside the python script rather than the result. I am running a basic python 2.7 httpserver.

This is my code:

Ajax call from javascript

$scope.login = function(userName,password){
    $http({
    method : "GET",
    url : "login.py"
}).then(function (response) {
    console.log(response.data);
});
};

Python script

import json
userName = ""
password = ""
form = cgi.FieldStorage()

if "userName" in form:
  userName = form[userName].value
if "password" in form:
  password = form[password].value

print json.dumps(userName)

and the output i receive is uploaded in the following image.

Thanks for the help in advance guys.enter image description here

Harsha Jasti
  • 1,114
  • 1
  • 9
  • 25

1 Answers1

0

You are literally getting the file instead of executing the file. I'm not sure how this server is running exactly (node.js ?), but you should execute the file in one way or another and not just send the content of the file.

Start off by reading the CGI documentation: https://docs.python.org/3.6/library/cgi.html

Joost
  • 3,609
  • 2
  • 12
  • 29