这是我试过的东西……
<html> <head> <title>bugstats.com</title> </head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://jquery-json.googlecode.com/files/jquery.json- 1.3.min.js"></script> <script type="text/javascript" > function hello(){ var myObject = {"method":"User.login",/* is this the right method to call? */ "params":[ { "login" :"user",/*should i include the login credentials here? */ "password" : "pass123","remember" : "True"} ] }; var enc = $.toJSON(myObject); $.ajax({"contentType":"application/json","data": enc,"crossDomain":"true","dataType": "json","url": "https://bugzilla.company.com/bugzilla/jsonrpc.cgi",/* is this correct or should it be https://bugzilla.company.com/bugzilla/jsonrpc.cgi?method=User.login? */ "type": "POST",success: function(){ alert("Hallelujah"); console.log(arguments); },error: function () { alert("Failed") } }); } function parseResponse(obj){ alert("Success") console.log(obj) } </script> <body> <h1>bugzilla.com</h1> <input type="button" onclick="hello()" value="Click"> </body>
阅读这篇JSONPRC,没有走远.
当我点击按钮 – 拨打电话,登录/做任何事情 – 我得到以下错误 –
OPTIONS https://bugzilla.company.com/bugzilla/jsonrpc.cgi 403 (Forbidden) jquery.min.js:19 XMLHttpRequest cannot load https://bugzilla.company.com/bugzilla/jsonrpc.cgi. Origin http://172.16.229.137 is not allowed by Access-Control-Allow-Origin.
根据我的理解,“Access-Control-Allow-Origin”是由于“同源策略”问题引起的,因此我应该使用“jsonp”.但是,Jsonp – 即脚本注入只能通过GET请求来完成.但是,如果我使用GET请求尝试相同的JS脚本 – 我得到以下内容:
code: 32610 message: "For security reasons,you must use HTTP POST to call the 'User.login' method."
对于如何通过Web服务进行连接/登录感到困惑,我显然在做一些愚蠢的事情,这里有一些重大错误..如果有人可以帮助我连接并获取错误详细信息,将会提供很多帮助.我从那时起就一直在这里现在8-10天..