简体   繁体   中英

Getting array from remote server location using Javascript

I am having one executable URL..when I hit that URL using GET type request that URL should return me Array in Javascript...

I have created one doGet() in remote server which returns JSON.stringfy(array); I tried this code...can anyone tells me how I can get that array?

fetch(myUrl,{method:'get',headers:{'content-type'-'application/x-www-form-urlencoded'},
mode:'no-cors'}).then(function (response){ console.log(response);
});

You need CORS permission to read data from a different origin so do not set mode:'no-cors' .

If you are writing an extension page — not a content extension script — such as a background page, popup, or options page then you can request cross-origin permissions :

By adding hosts or host match patterns (or both) to the permissions section of the manifest file, the extension can request access to remote servers outside of its origin.

 { "name": "My extension", ... "permissions": [ "https://www.google.com/" ], ... }

Aside: You are making a GET request so you have no request body and so shouldn't describe the type of content in the request body. 'content-type'-'application/x-www-form-urlencoded' is nonsense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM