<script> function test() { var name = document.getElementById('name').value; document.cookie = "name=" + name; console.log(document.cookie); document.open('chk_name.php','chk_name','width=100, height=100'); } </script>
this is chk_name.php
<?php echo "hi! this is chk_name.php"; echo $_COOKIE['name']; // echo "<script>window.close();</script>";?>
I want to check username. I use document.open(‘chk_name.php’); then I check username in chk_name.php by using cookie. but I have problem when user using their phones. document.open make a new window. It looks Ok in PC browser. but It looks terrible in phone browser. because they make a full screen. so I want to check username without openning new window. how can I check data using server(db) wihtout openning new window?
Advertisement
Answer
You can use ajax request for this purpose
function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("GET", "chk_name.php", true); xhttp.send(); }