如何修复从原件对XMLHttpRequest的访问已被CORS阻止

时间:2019-05-10 03:09:27

标签: android rest api cordova ionic-framework

我有function(ionic1)调用POST数据到RestAPI(WebAPI MVC)。在命令终端显示以下错误“ ionic cordova run android -device -l”。 但是我和邮递员测试没关系。

image error

function save(){

        jQuery.support.cors = true;
        var Patient = {
            Patient_Id: 5
            , Patient_Prefix: document.getElementById("txtprefix").selectedIndex
            , Patient_Name: $('#txtname').val()
            , Patient_Email: $('#txtemail').val()
            , Patient_Tel: $('#txtteldoc').val()
            , Patient_Address: $('#txtIP').val()
            , Patient_Birthday: $('#txthbd').val()
            , Patient_Username: $('#patientusername').val()
            , Patient_Password: $('#txtPassword').val()
            , Patient_TelFamily: $('#txttelfamily').val()
            , Patient_CardId: $('#txtcardid').val()
            , Patient_Allergy: $('#txtAllergy').val()
            , Patient_IsApprove: 0
            , Patient_IsApproveText: ""
            , Patient_Token: $('#txttoken').val()
        };

        $.ajax({
            url: uripatient + '/y',
            //xhrFields: 'withCredentials:true',
            type: 'POST',
            data: JSON.stringify(Patient),
            contentType: "application/json;charset=utf-8", //contentType: "application/json;charset=utf-8" "application/x-www-form-urlencoded; charset=UTF-8"
            success: function (data) {
              //  alert(data);
            },
            error: function (x, y, z) {
              //  alert(x + '\n' + y + '\n' + z);
            }
        });
    }

0 个答案:

没有答案