无法调用Ajax调用从服务获取数据

时间:2016-09-02 07:11:56

标签: html ajax

我有以下代码,我想从服务中获取数据。我已经设置了我从谷歌那里得到的一切。

function checkLicense() {
debugger
try {
    var _name = "aaa-bcs-edt"; //location.host;
    $.ajax({
        type: "POST",
        url: "http://mdc.abc.com/LicenseWebService.svc/IsLicenseValidByName",
        data: '{"DName":"' + _name + '"}',
        contentType: "application/json; charset=utf-8",
        crossDomain: true,
        dataType: "json",
        async: false,
        success: function (msg) {
            debugger
            var data = msg.d;
            if (data == "success") {
                licenseactivated = "success";
            }
            else {
                licenseactivated = "Fail";
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            debugger
            alert(errorThrown.toString());
        }
    });
} catch (err) {
    debugger
    alert(err.message.toString);
}

目:

<head>
    <title>Create Purchase Order</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta>
    <meta>
    <meta>
</head>

以下是错误的控制台日志: enter image description here

有人可以建议我吗?

1 个答案:

答案 0 :(得分:0)

您需要在服务器端启用cors标头。

http://www.codeproject.com/Articles/845474/Enabling-CORS-in-WCF