Q:

Cross-Origin Request Blocked error on sending post to an api using javascript

Hi i have an like this https://rdkportal.ccp.xcal.tv/build_images/cdl on sending a post request to it i will be able to get some information in json as response.
This is the format for sending it using linux
curl -u username:password https://rdkportal.ccp.xcal.tv/build_images/cdl -H "Content-Type: application/json" -H "Accept: application/json"  -X POST -d '{"image_name": "MX011AN_VBN_master_20160118234003sdy_NG", "recipients_list": "some_user@.com", "cdl": "PROD", "type": "tftp", "stb": { "ip4_address": "0.0.0.0", "ip6_address": "2001:558:4030:2:96d4:feff:fe7c:7500", "mac_address": "", "serial_number": "" }}'

I was success full in sending a POST request and receiving the response by executing the above curl command in a linux machine.
I am trying to do similar thing in javascript using ajax but i am getting the below error.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://rdkportal.ccp.xcal.tv/build_images/cdl. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Here's my code
$.ajax({
        type: 'POST',
        url: 'https://rdkportal.ccp.xcal.tv/build_images/cdl',
        crossDomain: true,
        data: '{"some":"json"}',
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        success: function(responseData, textStatus, jqXHR) {
            var value = responseData.someKey;
            alert('POST success');
        },
        error: function (responseData, textStatus, errorThrown) {
            alert('POST failed.');
        }
    });

I also dont know how to send the credentials with the request in ajax. Please help i am strucked up here. Thanks in advance.

A:

You can acheive these things in 3 ways:
1) You can install chrome plugin if server side code is not in your control means you guys are not handling it.
Link:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-ntp-icon
2). You can create proxy server and communicate using those new urls/api.
3). The 3rd and last and best is to allow Access-Control-Allow-Origin: * to either *(for giving access to all urls from any domain ), or Access-Control-Allow-Origin: 'your system ip if running locally else hostname' (for giving access to only that particular host)

