1

我们正在尝试通过 jQuery 创建票证,但遇到以下错误:

错误:http://itsmapdv.bmc.com:8008/jwt/login 的 XMLHttpRequest需要跨域资源共享 (CORS)。

代码:

function getAuthorisationCode(pstrUsername, pstrPassword) {
    //Get the auhorisation code from the server. We accept the user name and the password, and return the code.
    console.log("Starting GetAuthorization");
    var xmlhttp;
    xmlhttp = new XMLHttpRequest();


    //Define a POST request. Notice I set the last parameter to false, which means it goes out synchronously. I need this as I need
    //to wait until I get the code before moving on.
    xmlhttp.open("POST", "http://itsmapdv.bmc.com:8008/jwt/login", false);
    //Add a HTTP header to request to specify the content-type.
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    //Send the request. The POST body is included here.
    xmlhttp.send("username=" + pstrUsername + "&password=" + pstrPassword); //Failing here
    console.log(xmlhttp.responseText);
    //If we get HTTP200 back we're done and we can return the code.
    if (xmlhttp.status == 200) {
        return "AR-JWT " + xmlhttp.responseText;
    }
}

我们如何在这里进行这个 CORS 调用?

4

0 回答 0