I am creating a simple module for our senior project that checks whether an email already exists in the database. This is the important segment of my php file which displays the formated JSON:
die(json_encode(array(2 => "Email already taken!")));
For that example, that should return = {"2","Email already taken!"}
And here is the javascript code (that's embedded):
$(function() { $("#signin").submit(function() { // validate and process form here $.ajax({ type: "GET", url: "mailcheck.php", data: "email="+document.getElementById('email').value, success: function(data) { var parsed = $.parseJSON(data); //display message back to user here document.getElementById('msg').innerHTML = parsed.Msg; $("input#email").val(""); }, }); return false; }); });
The problem is, I always get 'undefined'. What's the problem?
die()also echo out the contents? codepad.viper-7.com/w3uR9Cdie()function echoes out its contents then it will exit, thus leaving the succeedingecho()ordie()statements not displayed.die(), could I useexit;instead? I tried exit and it also worked...