javascript
6 TopicsCORS policy: Response to preflight request - JavaScript/SharePoint Server
I have an issue connecting to my SharePoint server. This issue occurs whenever I try connecting my code from the frontend to the SharePoint server, I do not have a backend for this. Basically, I am trying to get the SharePoint API results directly via JavaScript. I am uncertain why this error keeps popping up. Is there something wrong with my IIS configuration? Please do help me on this! Thank you! This is my IIS configuration in the SharePoint Server: <httpProtocol> <customHeaders> <add name="X-Content-Type-Options" value="nosniff" /> <add name="X-MS-InvokeApp" value="1; RequireReadOnly" /> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol> Error Message: My code is as follows: function simpleSearchAPICall(searchUrl) { $.ajax({ url: searchUrl, type: "GET", contentType: "application/json; charset=utf-8", dataType: "json", complete: function(response){ console.log("URL", searchUrl) console.log(response); // Handle the response data here }, error: function(xhr, status, error) { console.error("ERROR:",error); // alert("An error occurred while making the request."); } }); simpleSearchAPICall("http://www.test.com/_api/search/query?querytext='test'") });671Views0likes0CommentsSharepoint CORS Policy issue persist even after ISS Configurations
I am currently trying to fetch my Sharepoint API via my code. However I am running into the issue below. I have already enabled the ISS Configurations as shown in the link below. However, the issue still persist. https://techcommunity.microsoft.com/t5/iis-support-blog/access-to-xmlhttprequest-from-origin-has-been-blocked-by-cors/ba-p/3800362 Error: index.html:1 Access to XMLHttpRequest at 'http://testing- sharepoint/Shared%20Documents/query%20result%20BEFORE.xml' from origin 'http://127.0.0.1:2233' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. My code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { function apiCallTest(searchValue) { const adminAccount = 'testUser'; const adminAccountPassword = 'testPassword'; const auth = btoa(`${adminAccount}:${adminAccountPassword}`); const testQuery = 'BEFORE'; const apiUrl= "http://testing-sharepoint/Shared%20Documents/query%20result%20BEFORE.xml" const headers = { 'Authorization': `Basic ${auth}`, // 'Accept': 'application/json;odata=nometadata', // 'Content-Type':'application/json', // 'Access-Control-Allow-Credentials':'TRUE', // 'Access-Control-Allow-Headers':'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization', // 'Access-Control-Allow-Origin':'*', // 'Access-Control-Allow-Methods':'GET,POST,PUT,OPTIONS' }; $.ajax({ url: apiUrl, headers: headers, method: 'GET', dataType: 'xml', success: function(data) { // Process the search results as needed console.log('Search Results:', data) }, error: function(xhr, textStatus, errorThrown) { console.log("Cannot connect") console.error('Error:', xhr, textStatus, errorThrown); } }); } function checkConnection(url) { if (navigator.onLine) { console.log(`You are online. Checking connection to ${url}...`); // You can attempt further actions here if needed } else { console.log('You are offline. Check your network connection.'); } } checkConnection("https://testing-sharepoint/_api/site"); apiCallTest(); }); </script> </head> <body style="background: black; color: aliceblue; font-size: 2rem;"> </body> </html>1.5KViews0likes0CommentsGetting the MArquee JQuery library to work
Hi I have a very simple javascript, Housed in @MikaelSvenson 's excellent script editor for the Modern UI. I am trying to get an announcement from the Announcements list to display on a modern UI Page from Right to Left across the page. Just like the old fashioned Marquee HTML element. But nothing is being displayed. CAn anyone see why ? <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/jquery.marquee/1.3.1/jquery.marquee.min.js"></script> <script type="text/javascript"> console.log("At start of REST Script"); $url = "https://<tenantname>.sharepoint.com"; $.ajax({ url: $url + "/_api/web/lists/getbytitle('Announcements')/items?select=*", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function(data) { console.log("Success"); console.log(data.d.results); var $dataArray = data.d.results; for (var $i in $dataArray) { console.log(data.d.results[$i].Title); var $str = $dataArray[$i].Body0; var $gtindex = $str.indexOf(">"); $gtindex = $gtindex + 1; $str1 = $str.substring($gtindex); console.log($str.substring($gtindex)); var $ltindex = $str1.indexOf("<"); console.log($ltindex); console.log($gtindex); var $length = $ltindex -$gtindex; var $innertext = $str1.substring(0,$ltindex); console.log($innertext); var $bodyHtml = "<li>" +$innertext + "</li>"; $("marquee").append($bodyHtml); } }, error: function(data) { console.log("Failure"); alert(JSON.stringify(error)); } }); $("#marquee").marquee(); console.log("At End of Script"); </script> <ul id="marquee" class="marquee" /> Apologies for some of the code I have been debugging it. Thanks Nigel1.2KViews0likes1CommentProperties do not display due to JSON JavaScriptSerializer error
I have a SharePoint online library that utilizes several lookup columns. The other day we started receiving errors in the modern view when trying to view the properties. The error we are getting is "Sorry, properties can not be displayed, having error: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.." If I look at the library in classic view everything appears to be operating correctly, modern just seems to be the issue. Any ideas on where I should be looking to find the source of the problem? I looked at the developer tools in Chrome (F12) and noticed there were a few 400 errors getting returned for the /GetList(@listUrl)/RenderListDataAsStream...... Not sure if that has anything to do with the problem or if it is just a symptom of the cause.9.2KViews0likes3CommentsAccessing SharePoint List via external html page using .ajax function but getting CORS error
I need to query SharePoint List from simple javascript, using .ajax call. I need to use a AD user credentials who will have read permissions to the SharePoint Site. I am doing something like this but getting a lots of errors. Any suggestions. var user = "****@AD2012.***"; var passwordtemp = "**********"; $.ajax({ url: siteURL + "/_api/web/lists/GetByTitle('"+ listName +"')/items" + filterQuery, method: "GET", headers: { "Accept": "application/json; odata=verbose" }, crossDomain: true, beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', make_base_auth(user, passwordtemp)); }, success: function (data) { // Doing something with data .. }}, error: function (data) { failure(data); } }); } // function ends ..2KViews0likes0CommentsSharePoint - Users have to click Save twice when create new Document Set
I am not sure what customization has been done on our SharePoint site but when user create new Document Set, there are 2 Save buttons, the 1st one is useless, the one at the bottom right is working. We are using SharePoint online. New site collection does not have this issue.3.3KViews0likes9Comments