dimanche 6 novembre 2016

Unable to call the Rest Api through AJAX my domain are diiferent

When i am calling the Rest Api from my local host using the ajax itshows some error.However the same works from the postman chrome extension.following code i am trying.

    function getdocumnets() {
        var url = "http://ift.tt/2fqGQDd";
        $.ajax({
            type: "POST",
            url: url,
            contentType: "application/json",
            data: {
                "Request":
    { "RequestPayload": {
        "ProposalId": "121345",
        "Type": "getMandatoryDocuments"

    }
    }
            }
            ,
            crossDomain: true,
            success: function (data) { console.log(data); },
            error: function (data) { console.log(data); },
            dataType: 'json',
            beforeSend: function (xhr) {
                xhr.setRequestHeader("Access-Control-Allow-Origin", 'PUT, GET, POST, DELETE, OPTIONS'),
                xhr.setRequestHeader("Access-Control-Allow-Origin", 'accept, content-type, x-parse-application-id, x-parse-rest-api-key, x-parse-session-token'),
                xhr.setRequestHeader('Access-Control-Allow-Origin', 'http://localhost:1390');
          // xhr.setRequestHeader('Access-Control-Allow-Origin','http://localhost:1390');
            },
            headers: {
                'Access-Control-Allow-Origin': 'http://localhost:1390'
            }
        });
    }

</script>

folowing Error I am getting:

    XMLHttpRequest cannot load http://ift.tt/2fdvEqA. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1390' is therefore not allowed access.




Aucun commentaire:

Enregistrer un commentaire