-2

i want to check username in database whether it is there or not while typing

i wrote php coding in same page..i have taken the username by javascript like var x=document.getElementById("username").value;

now how to pass value to php code.please give suggestion for this.

PSR
  • 39,804
  • 41
  • 111
  • 151

1 Answers1

0

you can use jQuery $.getJson and send Json Object to PHP script and use it there. The PHP can return Json value back to the Javascript so it can know how to handle it.

$.getJson('php_script.php', '{username:username}', function (returnJson) {
//here you do what you want with the returnJson object
}
Sharon
  • 88
  • 6
  • 1
    `'{username:username}'` is neither JSON nor an object. I suggest to pass an object (`{username:username}`), so that PHP can access the value via `$_GET['username']`. – Felix Kling Jul 04 '13 at 11:26