how to have a web.py python webservice return a jsonp call to jquery
Question: **So I'm trying to get a web.py based python webservice to send back a list
object trough JSONP after jQuery makes an ajax call to it.**

Problem is after reading up a lot of examples I'm still failing to understand
how to make it work. Here's the code I got I'm working with atm:

Javascript:

    
    
    xmlrpcproxy = 'http://0.0.0.0:1885/'; //Back To The Future III reference on the port :)
    
    jQuery.ajaxSetup ({
        url: xmlrpcproxy, // <--- returns valid json if accessed in the browser
        type: "GET",
        cache: false,
        contentType: "jsonp", // Pay attention to the dataType/contentType
        dataType: 'jsonp', // Pay attention to the dataType/contentType
        });
    jQuery.ajax({
        success: function(data) {
            console.log("You made it!");
        },
        error: function (xhr) {
            console.log("Error: " + xhr.statusText);
        }
    }).done(function(data){
        console.log(data);
        var firstoption = '<option value="select" selected>Please Select</option>';
        jQuery("select#ItemIDSelect").html(firstoption);
        var i;
        var erplist = JSON.parse(data);
        jQuery("responsearea").append(erplist);
        for (i = 0; i < erplist.length; ++i) {
                    jQuery("select#ItemIDSelect").append('<option value="' + erplist[i] + '">' + erplist[i] + '</option>');
        }
    });
    

Python web.py code

    
    
    #!/usr/bin/python
    # _*_ encoding: utf-8 _*_
    
    import web
    import xmlrpclib
    import json
    
    urls = (
      '/(.+)', 'index',
    )
    
    
    class index:
        def GET(self):
        #THE FOLLOWING IS A SUCCESFULL QUERY FOR DATA TO AN ERP SERVER
        server = '***.***.*.**' #hidden the openerp server for stackoverflow post
        username = 'admin' #the user
        pwd = 'admin'      #the password of the user
        dbname = 'demo'    #the database
    
    
    
        # Get the uid
        sock_common = xmlrpclib.ServerProxy ('http://%s:8069/xmlrpc/common'%(server))
        uid = sock_common.login(dbname, username, pwd)
    
        #replace localhost with the address of the server
        sock = xmlrpclib.ServerProxy('http://%s:8069/xmlrpc/object'%(server))
    
        # Unactive all product with a stock = 0.0 and using the ancient code
    
        ids = sock.execute(dbname, uid, pwd, 'res.partner', 'search', [])
    
        p_ids = sock.execute(dbname, uid, pwd, 'res.partner', 'read', ids, ['name'])
        #END OF THAT PARTICULAR QUERY
    
        a=[]
        for p in p_ids:
            a.append(p['name'])
        b = json.dumps(a)
        return 'some_function(' + b + ')
    

example: typical content of **b**

    
    
    ["The Jackson Group's Project", "Research & Development", "E-Learning Integration", "Website Design Templates", "Data Import/Export Plugin", "1", "Project XXX", "Contract Agrolait", "Project : Agrolait"]
    

Can anyone help? As I understand there is a way of setting the name of the
function in the javascript side so perhaps that would be one way to solve it,
setting that to some_function I mean. But all idea's/ways as how to fix this
are welcome ofc, so far nothing I tried worked >.<

Thanks for reading!


Answer: JQuery seems to provide callback function name in `callback` query param. And
make sure to set correct content type header.

    
    
    callback_name = web.input(callback='callback').callback
    web.header('Content-Type', 'application/javascript') 
    return '%s(%s)' % (callback_name, b)
    

