मैं 'नो-कॉर्स' मोड के साथ fetch polyfill का उपयोग कर रहा हूं और प्रतिक्रिया स्थिति प्राप्त कर रहा हूं 0. डेवलपर टूल में मैं देख सकता हूं कि प्रतिक्रिया का अनुरोध किया गया डेटा है।प्रतिक्रिया स्थिति = 0 मोड के साथ fetch polyfill का उपयोग करके: 'नो-कॉर्स'
क्लाइंट साइड कोड:
const BASE_CONFIG = {
credentials: 'include',
mode: 'no-cors'
};
let checkStatus = (response) => {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
throw error;
}
};
function GET(url, urlParams={}, config={}) {
let requestConfig = {
method: 'get'
};
Object.assign(requestConfig, BASE_CONFIG, config);
return fetch(url, requestConfig)
.then(checkStatus)
.then(parseJSON);
}
GET('http://other.domain,{})
Beckend NodeJS (Express.js) सरलीकृत प्रतिक्रिया हैंडलर:
function getData(req, res) {
var responseData = {data: 'test'};
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.writeHead(200, {"Content-Type": "application/json"});
return res.end(JSON.stringify(responseData));
}
कोई विचार क्या मैं गलत कर रहा हूँ? धन्यवाद!
जब भी आप 'नो-कॉर्स' का उपयोग करते हैं, तो यह 'ओपेक' प्रतिक्रिया वापस भेजता है और आप जेसन नहीं जा सकते हैं। निश्चित नहीं है कि उस मामले में 'नो-कॉर्स' का उपयोग क्या है? किसी को? – morgs32