I read that question(click). I read in similar articles. But it's not sending the data.
The program I want to do:
- I'm trying to make a login program.
- I have a JSON file that stores username and password data in it.
- From the outside, I can capture the data in the JSON file. (not problem)
- But I want to send the data. (this problem)
- The system does not issue an "error" warning. But it does not send the data in the JSON file.
Example JSON file:
{
"jack":"jack123",
"rick":"rick123",
"maria":"maria123"
}
HTML CODE:
<input type="text" id="username" placeholder="username">
<input type="text" id="password" placeholder="password">
<button onclick=run()>CLICK RUN</button>
<button onclick=run1()>CLICK RUN1</button>
JAVASCRIPT CODE:
function run1(){
var username = $("#username").val();
var password = $("#password").val();
let xmlRequest,obj;
xmlRequest = new XMLHttpRequest();
xmlRequest.onreadystatechange = function(){
if(this.readyState === 4 && this.status === 200){
obj = JSON.parse(this.responseText);
var res = obj[username];
if(res == password){
alert(`Welcome ${username}`);
}
}
}
xmlRequest.open("GET","http://localhost/deneme/info.json",true);
xmlRequest.send();
}
function run(){
var username = $("#username").val();
var password = $("#password").val();
let xmlRequest,obj;
xmlRequest = new XMLHttpRequest();
var url = "http://localhost/deneme/info.json";
xmlRequest.open("POST", url, true);
xmlRequest.onreadystatechange = function(){
if(this.readyState === 4 && this.status === 200){
obj = JSON.parse(this.responseText);
}
}
var data = JSON.stringify({username:password});
xmlRequest.send(data);
}
NOTE: I don't know PHP.