cross domain call using using python and make ajax call to the python to read data
Question: I am trying to make an ajax request to a python script running in the same
webserver. The call happens fine. I am using python to make the cross domain
call to return some data back. with .success() i get back all the content of
the script file. I could do this PHP quite easily but I am trying to use
python for the sake of learning it.

My python looks like this

    
    
    import urllib.request
    
    def main():
        r = urllib.request.urlopen("http://some url").read()
        print(r)
    
    main();
    

My ajax looks like this

    
    
    $('div_something').on('click', function(){
    
            $.ajax({
                    type: "POST",
                    dataType: 'html',
                    url: "getproduct.py",
                }).done(function(data){
                    $('div').html(data);
    
                });
    
        });
    


Answer: I'd suggest using [requests](http://docs.python-requests.org/en/latest/),
Python's native support for this isn't friendly.

Edit: I missed the part about success(). Is this what you meant?

    
    
    >>> import requests
    >>> response = requests.post("http://some url")
    >>> if response.status_code == requests.codes.ok:
            print(response.text)
    >>> elif response.status_code == 404:
            handle_error()
    

