使用jquery

时间:2017-06-22 13:51:29

标签: jquery rest api remedy

我们正在尝试通过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调用?

0 个答案:

没有答案