I have a problem with a SharePoint-Hosted App (App for SharePoint) developed by me. SharePoint version is 2013.
The app web is: http://app-12a34567bcde8f.sharepoint.local/sites/DEV/HelloWorld
The host url is: http://dev.local/sites/DEV
The example script is written in JSOM:
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);
});
Info messages in console.
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.
Error message in console.
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
Console.Log result:
"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}
I can't understand this, because the method with REST and SP.RequestExecutor doesn't work, too.
-1003 App Web is not deployed for this app's request url http://dev.local.
Example:
var executor = new SP.RequestExecutor('http://dev.local');
executor.executeAsync({
url: "http://dev.local/_api/search/query?querytext='*'&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);
}
});
And jQuery said "401 UNAUTHORIZED":
$.ajax({
crosDomain: true,
url: "http://dev.local/_api/search/query?querytext='*'&refinementfilters='contenttype:equals (\"SPFolder\")'",
success: function(e) {
console.log('Success', e);
},
error: function(e) {
console.log('Error', e);
}, dataType:'json'
});
I want only execute one search query and use the SP.ClientContext normally.
Thanks in Advance for any help!
Take a look at this article: Access SharePoint 2013 data from add-ins using the cross-domain library. Alternatively, you might try to set Access-Control-Allow-Origin: * on the IIS that hosts dev.local/sites/DEV.
I needed to use SP.ProxyWebRequestExecutorFactory (Cross Domain) to get my query to work. There is an example on this site. Explain when to use WebRequestExecutorFactory & SP.ProxyWebRequestExecutorFactory
User contributions licensed under CC BY-SA 3.0