Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Im making... something and it needs XmlHttpRequests.
One of them works perfectly, but the other one doesnt

Sorry for censoring some of the stuff its links and stuff...
URls to stuff that shouldnt be seen...







uh

What I have tried:

JavaScript
// this one works
var xhttp = new XMLHttpRequest()
xhttp.onload = function () {
  let data = this.responseText
  let jsonData = JSON.parse(data)
  let *** = jsonData[********].img
  document.getElementById("*******").src = ***
}
xhttp.open("GET", "https://**********************")
xhttp.send()

// this one's responseText is null
var x = new XMLHttpRequest()
var data
x.onload = function () {
  data = this.responseText
  let jsonData = JSON.parse(data)
  data = jsonDat
}
xhttp.open("GET", "https://*************************************")
xhttp.send()
for (var i = 0; i > data.length; i++) {
  a = data[i]
  if (a.****** == ******) {
    ********** = a.******
  }
}
Posted
Updated 19-Jul-21 7:27am
Comments
Richard MacCutchan 2-Jul-21 8:58am    
Probably because the addresses are all asterisks. Seriously how do you expect anyone to answer such a question? Not only have you hidden the URIs but you have not given us any clue as to what "doesn't work" means.
A-Games 2-Jul-21 9:08am    
this.responseText is null
Richard MacCutchan 2-Jul-21 9:21am    
Very interesting. And what are we supposed to guess from that?
A-Games 2-Jul-21 9:08am    
and the asterisks is because the files contain passwords
A-Games 2-Jul-21 9:09am    
and in the code i said this:
// this one's responseText is null

There's a secret error somewhere in your secret code. You need to fix that.

Seriously, how do you expect anyone to help you fix an error with code we can't see? The problem is almost certainly with your server-side code, not the redacted client-side code you've shown.

You need to debug your code to diagnose and resolve the problem. We cannot do that for you.

NB: Unless you need to support ancient browsers like Internet Explorer, you may find it easier to use the Fetch API[^], possibly combined with an async function[^].
 
Share this answer
 
Comments
A-Games 12-Jul-21 21:37pm    
The file is a text file
A-Games 12-Jul-21 21:38pm    
i think...
A-Games 12-Jul-21 21:39pm    
they're both JSON files
A-Games 12-Jul-21 21:39pm    
but i need to read the file as text then parse it to JSON
Richard Deeming 13-Jul-21 4:10am    
And?

A JSON file is just a text file with a particular format of data in it.

You still haven't provided anywhere near enough information for anyone to help you.
This is the second one's code.
JavaScript
var x = new XMLHttpRequest()
var data
x.onload = function () {
  data = this.responseText
  let jsonData = JSON.parse(data)
  data = jsonDat
}
xhttp.open("GET", "https://*************************************")
xhttp.send()
for (var i = 0; i > data.length; i++) {
  a = data[i]
  if (a.****** == ******) {
    ********** = a.******
  }
}

News flash: IM AN IDIOT
Note how the second one declares the variable X, but not XHTTP
Im tryna open and send the first one from the second one.
Lel.
I dont understand how none of you caught that...
I guess I didnt either so...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900