0

Maybe i am wrong but i can not find anyone who wants to display a json message just in json format from url on the page except for me. I have a webshop in html, javascript and css. I am looking for some code example to display the json message just on the page. I don't want to parse the json into html or what else. I just want to display the json message as it is like this format: {"success":0,"message":"User not known"}. This message above is the url response from my php database in xampp. Below is my code and it works good, the problem is that this code is static. I am looking for some dynamic solution where you enter the url and it responds with json message. Any help is appriciated.

this is my login.html

if(form.id.value == "" || form.pass.value == "")  {       
alert("Empty details!");
}else if (form.id.value=="johan" && form.pass.value=="123") {             
location="Page2.html" 
} else  { alert("Wrong username or password!")
       }
           }

and this is the json read:

// 1 - read josn:
var my_json_output = {"success":1,"message":"Vol","Username":"jan","UserSurname":"janman"}',
json_yes.succes json_yes = JSON.parse(my_json_output);
    var my_json_output = '{"success":0,"message":"User_Unknown"}',
    json_no = JSON.parse(my_json_output);
        if(json_no.success == 1) { alert("Welcome, " + s + json_yes.Username);
        }else if(json_no.success == 0) { alert("Try again");     
}        
  • Pretty-Printing JSON with PHP : http://stackoverflow.com/questions/6054033/pretty-printing-json-with-php – Lion King Jul 04 '15 at 12:24
  • What you're looking for is how to serialize the data you're reading from your database into json. We need more code showing how your reading the data from your database. – Nasreddine Jul 04 '15 at 12:42
  • Hi Naser, On your request i added some more codes. I hope this enough is otherwise i will give more details if needed. Thanks in advance. – Darla_user2841780 Jul 04 '15 at 19:56

1 Answers1

0

Now i could find the answer and will share with others: just make a variable from XMLHttpRequest(); and use that variable for the message: myconnect = new XMLHttpRequest();