开发者

Can someone explain this code?

$.post("include/email_validate.inc.php", { email: $('#email').val() }, function(response){

if(response=="email_exits") { 开发者_开发问答 alert("E-mail Address Already Registered"); return false; } else if(response=="invalid_email") { alert("Invalid E-mail Address" ); return false; } });

Can you explain the above code? I think it is related with validation. What I am not understanding is specifically this line...

$.post("include/email_validate.inc.php", { email: $('#email').val() }, function(response)

Please tell me what this code is doing?


That line is jQuery code to send an AJAX bosed request. Check out the jQuery manual on $.post for more information on that function.

Specifically, this code seems to send a request to the server containing an email address, and receive a response based on whether that email is unique and/or valid. Technically, this code could do anything because we can't see the PHP handler or expected input, but the messages suggest e-mail validation and storage.

Note: The email address it sends will be in the input box that has X/HTML looking something like this:

<input type="text" name="email" id="email" />

More Info

Actually, that little title is misleading; there is no more info we can give you. This code relies heavily on some backend code which we cannot see. You must check the contents of include/email_validate.inc.php for more information (feel free to post the contents of this file, just make sure to remove any database username or password info), but without doing so this is as much information as anyone here can hope to give you.


It looks like this method is passed a response [function(response)] and then conditionally test's the string value and provides an alert for two cases. However, this code snippet doesn't cover the case where the "response" string doesn't equal either of the two tests.

Possibly used in a ajax callback, where the server side file, email_validate.inc.php processes the client's input and then sends back a response for the client side to generate for the user.


The code makes a POST request to "include/email_validate.inc.php" with the value of #email. It looks like the script then responds with either "email_exits" or "invalid_email" to, I would assume, validate an email address.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜