したがって、jQueryがajax呼び出しを行った後、JSONPを介してリストオブジェクトを送り返すために、web.pyベースのpython Webサービスを取得しようとしています。
問題は、多くの例を読んだ後でも、それを機能させる方法をまだ理解できていないことです。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 コード
#!/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 + ')
例: 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"]
誰でも助けることができますか?私が理解しているように、JavaScript側で関数の名前を設定する方法があるので、おそらくそれを解決する1つの方法であり、それを some_function に設定します。しかし、これを修正する方法に関するすべてのアイデア/方法は歓迎されています。
読んでくれてありがとう!