I am using Visual Studio 2010 and MVC 3 with AJAX / JQuery. The problem I am facing is that the code sends something twice. This only happens when you post something, and then do it again.
Here is my JS:
$(document).ready(function () {
BindEvents();
});
function BindEvents() {
$('#OpenCommentDialog').click(function (event, ui) {
var id = $(this).attr('data');
$('#NewCommentDialog').dialog({
open: function (event, ui) {
$('#BugID').val(id);
var form = $('form', '#NewCommentDialog');
form.submit(function (e) {
var comment = form.serialize(true);
CreateComment(comment);
return false;
});
}
});
$('#NewCommentDialog').dialog('open');
return false;
});
}
function CreateComment(comment) {
if (comment != null) {
$.post('/Comments/Create/', comment, function (data) {
if (data == 'Success') {
var id = $.parseQuery(comment);
GetComments(id.BugID);
$('#NewCommentDialog').dialog('close');
}
});
}
}
function GetComments(id) {
$('#Comments').find('tr').remove();
$.getJSON('/Comments/GetComments', { id: id }, function (data) {
if (data != null) {
if (data.length > 0) {
$('#CommentListTemplate').tmpl(data).appendTo('#Comments');
}
}
});
}
My HTML page has a jQuery dialog that calls the CreateCommentPartial.cshtml file. When the user fills it, he calls the CreateComment function, which then calls GetComments and updates the comments after the publication of a new one.
, . " ", , "CreateComment" , "GetComments" . Firebug .
? (F5) , . . , .
user634351