SP.ClientContext on host web failed because of Cross Origin Resource Sharing (CORS)
<p>I have a problem with a SharePoint-Hosted App (App for SharePoint) developed by me.
SharePoint version is 2013.</p>

<p>The app web is: <code>http://app-12a34567bcde8f.sharepoint.local/sites/DEV/HelloWorld</code>
The host url is: <code>http://dev.local/sites/DEV</code></p>

<p>The example script is written in <strong>JSOM</strong>:</p>

<pre><code>var clientContext = new SP.ClientContext('http://dev.local/sites/DEV');
var contextSite = clientContext.get_site();
clientContext.executeQueryAsync(function(e) {
    console.log('Success', e);
}, function(e) {
    console.log('Error', e);
});
</code></pre>

<p><strong>Info messages in console.</strong></p>

<pre><code>SEC7118: XMLHttpRequest for http://dev.local/sites/DEV/_api/contextinfo required Cross Origin Resource Sharing (CORS).
SEC7119: XMLHttpRequest for http://dev.local/sites/DEV/_api/contextinfo required CORS preflight.
</code></pre>

<p><strong>Error message in console.</strong></p>

<pre><code>SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
</code></pre>

<p><strong>Console.Log result:</strong></p>

<pre><code>"Error"
[object Object] {$1C_0: true, $1F_0: Object {...}, $1o_0: null, $1p_0: null, $1r_0: Object {...}, $1u_0: null, $1X_0: false, $29_0: "Javascript ...", $2A_0: null, $2I_0: false, $2N_0: 180000, $2T_0: null, $8_0: null, $F_0: Object {...}, $F_1: null, $N_1: Object {...}, $v_0: null, $w_0: "http://dev...", $x_0: null}
</code></pre>

<p>I can't understand this, because the method with REST and SP.RequestExecutor doesn't work, too.
<code>-1003 App Web is not deployed for this app's request url http://dev.local.</code></p>

<p><strong>Example:</strong></p>

<pre><code>var executor = new SP.RequestExecutor('http://dev.local');
executor.executeAsync({
    url: "http://dev.local/_api/search/query?querytext='*'&amp;refinementfilters='contenttype:equals (\"SPFolder\")'",
    method: 'GET',
    headers: 'application/json; odata=verbose',
    success: function(a) {
        console.log('Finish', a);
    },
    error: function(data, errorCode, errorMessage) {
        console.log('Error', data, errorCode, errorMessage);
    }
});
</code></pre>

<p><strong>And jQuery said "401 UNAUTHORIZED":</strong></p>

<pre><code>$.ajax({
    crosDomain: true,
    url: "http://dev.local/_api/search/query?querytext='*'&amp;refinementfilters='contenttype:equals (\"SPFolder\")'",
    success: function(e) {
        console.log('Success', e);
    },
    error: function(e) {
        console.log('Error', e);
    }, dataType:'json'
});
</code></pre>

<p>I want only execute one search query and use the SP.ClientContext normally.</p>

<p><em>Thanks in Advance for any help!</em></p>