Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question

marked as duplicate by CBroe, Felix Kling, Marcel Korpel, JE SUIS CHARLIE, freejosh Jul 4 '13 at 13:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

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
}
share|improve this answer
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 4 '13 at 11:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.