I'm currently working in eclipse and I'm making a component for Lumira designer in JavaScript. Beforehand I made a function that can write away data to my database (this one worked fine).
Now I'm trying to make a function to fetch this data back from the server. The problem is I try to see my data with an alert or in the console log but everytime I fetch something my alert either doesn't pop up or is empty and the console log is also empty. But when I check my network it always says that everything is fetched and I can see my objects(see picture below).
My question is why can't I see them in my alert or console? You can find my code and an image of the network below
Fetch I tried to use:
getButton.on("click", function() {
fetch('https://xxxxxx/myphpfile.php').then(
function(response){
alert(response)
return response.json();
}).then(function(jsonData){
alert(jsonData)
//handle json data processing here
});
xmlhttprequest I tried before:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
alert(xhr.responseText)
var resp = xhr.responseText
arr = JSON.parse(resp);
alert(arr);
}
}
xhr.open('GET', 'https://xxxxxx/myphpfile.php', true);
xhr.send(null);
Seems like using an Ajax call did the job for me
var dataOBJECTNAME='';
$.ajax({
url: 'http://your_webservice/GETALL_OBJECTS',
data: '',
success: function (resp) {
dataOBJECTNAME = resp;
},
error: function () {}
});
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.