jquery post going in loop
<p>I've this code which I'm using to post a message on 'Enter' key press, but it's going on loop and instead of posting one message it's posting it multiple times randomly.</p>

<p>This is the function I'm calling in on <code>&lt;input id='txtsendmsg" + i + "' placeholder=\"Write a comment...\" onkeypress='PostMessage(event,"+i+");'  class='msgtxt'&gt;&lt;/input&gt;</code> any help would be appreciated.</p>

<pre><code>function PostMessage(event,key) {
    $('#txtsendmsg'+key).on("keypress", function (e) {
        if (e.which == 13) {
            var msgid = $(this).siblings('.msgid').val();
            var msgtxt = $(this).val();
            $.ajax({
                url: "student_post_login.aspx/funPostMessage",
                data: 'postd=' + "Y" + '&amp;msgid=' + msgid + '&amp;msgtxt=' + msgtxt,
                success: function (data) {
                    if (data) {
                        displayData();
                    }

                },
                failure: function (response) {
                    alert("Faliure:");
                },
                error: function (response) {
                    alert(response);
                }
            });
            e.preventDefault();
        }

    });
}
</code></pre>
