I want to use javascript to retrieve a json object from a python script
Ive tried using various methods of ajax and post but cant get anything working.
For now I have tried to set it up like this
My Javascript portion:
I have tried

$.post('./cgi-bin/serverscript.py', { type: 'add'}, function(data) {
              console.log('POSTed: ' + data);
  });

and

$.ajax({
                          type:"post",
                          url:"./cgi-bin/serverscript.py",
                          data: {type: "add"},
                          success: function(o){ console.log(o); alert(o);}
                  });

My Python 

import json  import cgi import cgitb cgitb.enable()  data = cgi.FieldStorage()
req = data.getfirst("type")  print "Content-type: application/json" 
  print  print (json.JSONEncoder().encode({"status":"ok"}))

I am getting a 500 (internal server error)
Have you checked your host's server logs to see if it's giving you any output?
Before asking here, a good idea would be to ssh to your host, if you can, and running the program directly, which will most likely print the error in the terminal.
This is far too general at the moment, there are so many reasons why a CGI request can fail ( misconfigured environment, libraries not installed, permissions errors )
Go back and read your servers logs and see if that shines any more light on the issue.
Running CGI Python Javascript to retrieve JSON object