2016-12-07 66 views
1

我想從我的html文件中調用一個使用javascript的python方法。以下是我的html文件:JavaScript XML-RPC調用沒有執行

<html> 
<head> 
<title>Gadget</title> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script type="text/javascript" src="xmlrpc.js"></script> 
</head> 
<body> 

<button onclick="call()">Select</button> 
<script> 
function call() { 
     $.xmlrpc({ 
      url: 'my_odoo_server', 
      methodName: 'web_login', 
      params: ['admin', 'i-011d151e9af5b5588'], 
      success: function(response, status, jqXHR) { 
     console.log(response) 
}, 
      error: function(jqXHR, status, error) {} 
     }); 
} 
</script> 
</body> 
</html> 

但是xml-rpc調用並沒有完全執行。請幫忙解決這個問題。

這裏是控制檯圖像。

enter image description here

+0

是否有錯誤? –

+0

我添加了我的控制檯鏡像。請檢查。 –

+0

我的代碼沒有出現任何錯誤。在我的服務器上發送請求,我得到了一個沒有問題的迴應。發送到另一個雖然我得到「訪問控制允許頭」錯誤這是正常的。 「Access-Control-Allow-Headers」是你的問題嗎? – Strahdvonzar

回答

0

首先,你應該在你的base.xml文件擴展視圖,例如:

<t t-extend="ListView.buttons"> 
t t-jquery=".oe_list_buttons" t-operation="append"> 
    <button type="button" oe_button oe-c1>My button</button> 
</t> 

,那麼你從JS調用的函數:

var $c_1_button = this.$buttons.find(".oe-c1"); 

    $c_1_button .click(function() { 

      var mod=new instance.web.Model("your.model"); 
      mod.call("your_python_function",[params],{}).done(function(res) { }); 
+0

我無法對我的服務器文件進行任何更改。我必須使用javascript xml-rpc調用來調用odoo登錄方法。 –