How to make the function send one request and not accumulating, multiplying each time?

Here is the code. First comes one answer. The second time two. Read four. Eight. Sixteen....
Twisted, the spit does not turn out. What's wrong? But how? Thank you.

$(function(){
 $('input[name="email"], input[name="login"]').focus(function() {
 $(this).keypress(function(e) {
 if(e.keyCode==13) {
regg();
}
});
});

regg function(){
 var sendData = {};
 sendData.email = $("input[name='email']").val();
 sendData.login = $("input[name='login']").val();
$.post(
"/reg.php",
sendData
function(data)
{
if(data)
{
 data = $.parseJSON(data);
 var otvet =";
 $.each(data, function(i, val)
{
 otvet = val;
console.log(otvet);
 }); 
}
});
};
July 2nd 19 at 13:33
3 answers
July 2nd 19 at 13:35
Solution
Each time you focus, you create event "when you press Enter". The event should only be created once
Thank you. There is not sought, it turns out. :) - tanner7 commented on July 2nd 19 at 13:38
July 2nd 19 at 13:37
Better somehow.. it is not clear why still need to catch focus
$('input[name="email"], input[name="login"]').keypress(function(e) {
 if(e.keyCode==13) {
regg();
}
 });
Thank you, you are absolutely right. So the above is also suggested. Thanks again. - tanner7 commented on July 2nd 19 at 13:40
July 2nd 19 at 13:39
Do not hang up the event handlers inside event handlers)
Or if you really need to do is remove the old event handlers

Find more questions by tags JavaScriptjQueryAJAX