这是我到目前为止尝试过的。

<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-即,脚本注入(inject)只能通过GET请求完成。但是,如果我尝试使用GET请求使用相同的JS脚本,则会得到以下内容:
code: 32610
message: "For security reasons, you must use HTTP POST to call the 'User.login' method."

对于如何通过Web服务进行连接/登录感到困惑,我显然在做一些愚蠢的事情,这里主要是错误的..如果有人可以帮助我进行连接并获取错误详细信息,那将是非常有用的帮助。现在8-10天.. :(

供引用:
  • 我无权访问服务器
  • 我在客户端设置上,正在访问Bugzilla服务器

  • 其他链接,

    Ajax Call

    Loggin In

    BugzillaApc

    Google Groups - Live conversation

    最佳答案

    您需要使用Bugzilla_loginBugzilla_password参数对每个调用进行身份验证,这将使用jsonp进行GET。以User.get为例,您的调用将如下所示:

    // Method parameters
    var params = [{
      /* The authentication parameters */
      "Bugzilla_login": "YourUserName",
      "Bugzilla_password": "YourPassword",
      /* The actual method parameters */
      "ids": [1, 2]
    }];
    var myObject = {
      "method": "User.get",
      "params": JSON.stringify(params)
    };
    
    $.ajax({"contentType": "application/json",
        "data": myObject, /* jQuery will handle URI encoding */
        "crossDomain": "true",
        "dataType": "jsonp", /* jQuery will handle adding the 'callback' parameter */
        "url": "https://bugzilla.company.com/bugzilla/jsonrpc.cgi",
        "type": "GET",
        ...
    

    您必须这样做,因为:
  • 您将进行跨域调用
  • 因为您无法设置Access-Control-Allow-Origin之类的东西,所以您必须通过jsonp(或代理,但jsonp更简单)来完成此操作
  • jsonp一定是GET请求,而不是POST

  • 相关文档:
  • Connecting via GET-您将仅限于检索信息,更改需要POST调用。
  • Logging in via Bugzilla_login and Bugzilla_password
  • 10-05 21:07
    查看更多