Click here to Skip to main content
15,502,221 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionRedirect with (Page Visibility API) Pin
ab smine19-Mar-21 11:38
ab smine19-Mar-21 11:38 
QuestionNode-Schedule Module Can't Cron Job Scheduled Long Time Pin
Barış KAHRAMAN19-Mar-21 11:02
Barış KAHRAMAN19-Mar-21 11:02 
QuestionCalculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 4:31
Krasimir Dermendzhiev16-Mar-21 4:31 
AnswerRe: Calculation in javascript Pin
Richard Deeming16-Mar-21 5:39
mveRichard Deeming16-Mar-21 5:39 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 22:36
Krasimir Dermendzhiev16-Mar-21 22:36 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev30-Mar-21 5:22
Krasimir Dermendzhiev30-Mar-21 5:22 
QuestionJavascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027614-Mar-21 22:50
Member 1510027614-Mar-21 22:50 
AnswerRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming14-Mar-21 23:39
mveRichard Deeming14-Mar-21 23:39 
Your comment for the xhttp.open line is inaccurate and misleading. The third parameter has nothing to do with cookies; it simply controls whether the request is asynchronous or not:
XMLHttpRequest.open() - Web APIs | MDN[^]

The withCredentials property has no effect on same-site requests:
XMLHttpRequest.withCredentials - Web APIs | MDN[^]

You're not actually logging any details of the error. Have you checked the network request to see what the actual error is, or are you just assuming it's a CORS issue?


I'd recommend switching to the Fetch API instead:
Fetch API - Web APIs | MDN[^]
Using Fetch - Web APIs | MDN[^]

It's supported pretty much everywhere except Internet Explorer. If you need to support IE, there's a polyfill available[^].

In modern browsers, cookies for same-origin requests should be included by default. If you're using an older browser (prior to April 2018), you may need to supply the credentials:'same-origin' init option[^].
JavaScript
const loadLocalXMLCookie = async function(){
    const url = "jsondata.php";
    
    const response = await fetch(url, {
        method: 'GET',
        cache: 'no-cache',
        credentials: 'same-origin'
    });
    
    if (!response.ok) {
        const errorMessage = await response.text();
        console.error(response.status, response.statusText, errorMessage);
        return;
    }
    
    const responseText = await response.text();
    document.getElementById('outputElement').innerHTML = responseText;
};




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027615-Mar-21 0:11
Member 1510027615-Mar-21 0:11 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming15-Mar-21 0:29
mveRichard Deeming15-Mar-21 0:29 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027615-Mar-21 8:56
Member 1510027615-Mar-21 8:56 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming15-Mar-21 23:31
mveRichard Deeming15-Mar-21 23:31 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027616-Mar-21 7:49
Member 1510027616-Mar-21 7:49 
Questionif statement not working Pin
chizzy4211-Mar-21 8:53
chizzy4211-Mar-21 8:53 
AnswerRe: if statement not working Pin
NotTodayYo11-Mar-21 9:24
NotTodayYo11-Mar-21 9:24 
AnswerRe: if statement not working Pin
W Balboos, GHB11-Mar-21 9:45
mveW Balboos, GHB11-Mar-21 9:45 
GeneralRe: if statement not working Pin
chizzy4213-Mar-21 5:03
chizzy4213-Mar-21 5:03 
GeneralRe: if statement not working Pin
Member 1510027615-Mar-21 9:15
Member 1510027615-Mar-21 9:15 
GeneralRe: if statement not working Pin
chizzy4217-Mar-21 3:28
chizzy4217-Mar-21 3:28 
QuestionBeginner 5 Project idea Pin
Member 1373246628-Feb-21 15:29
Member 1373246628-Feb-21 15:29 
AnswerRe: Beginner 5 Project idea Pin
Richard MacCutchan28-Feb-21 22:37
mveRichard MacCutchan28-Feb-21 22:37 
AnswerRe: Beginner 5 Project idea Pin
Scott Butchers19-Mar-21 4:26
Scott Butchers19-Mar-21 4:26 
QuestionHow to navigate to next search term in angular with up and down arrow buttons? Pin
shruti devurkar18-Feb-21 6:54
shruti devurkar18-Feb-21 6:54 
SuggestionRe: How to navigate to next search term in angular with up and down arrow buttons? Pin
CHill6018-Feb-21 6:55
mveCHill6018-Feb-21 6:55 
QuestionTrying to read a value that is coming from html() function from Table Cell Id Pin
simpledeveloper17-Feb-21 20:42
simpledeveloper17-Feb-21 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.