Welcome to WebmasterWorld Guest from 54.226.238.178

Forum Moderators: open

Message Too Old, No Replies

jquery dialog post being duplicated

     
11:50 am on Jul 25, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 9, 2006
posts:55
votes: 0


Ths first time i make a post, the post submits fine. I then close the dialog window and click link to reopen and when i submit data again, it duplicates it and adds it twice. This behaviour just seems to keep adding a duplidcte each time. for example, post1 then post1+post1 then post1+post1+post1. Hope you get the idea. If someone could check my code, i would be grateful. Many thanks

// Feedback form

function feedbacknew() {

$("#fb_form").dialog({
autoOpen: false,
resizable: true,
modal: true,
title: 'Submit a feedback request',
width: 480,
beforeclose: function (event, ui) {
$("#fb_message").html("");


},
close: function (event, ui) {
$("#fb_message").html("");
$("#feedback").get(0).reset();
}

});

$('#fb_submit').click(function () {

var name = $('#fb_uname').val();
var client = $('#fb_client').val();
var department = $('#fb_department').val();
var email = $('#fb_email').val();
var position = $('#fb_position').val();
var feedback = $('#fb_feedbacknew').val();
var data = 'fb_uname=' + name +
'&fb_client=' + client +
'&fb_department=' + department +
'&fb_email=' + email +
'&fb_position=' + position +
'&fb_feedbacknew=' + feedback;
$.ajax({
type: "POST",
url: "feedback.php",
data: data,
success: function (data) {

$("#feedback").get(0).reset();
$('#fb_message').html(data);

//$("#form").dialog('close');
$("#flex1").flexReload();

},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
return false;

});

$("#fb_form").dialog('open');

}
1:13 pm on July 25, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4988
votes: 12


Are you calling feedbacknew multiple times? If so, then it will add another onclick listener to #fb_submit each time feedbacknew is called, thereby causing duplicate posts.
2:16 pm on July 25, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 9, 2006
posts:55
votes: 0


hi. I am calling from a on:press and I am calling it once. For example, click->open dialog form->submit form-> close form. If i open a new form without refreshing the browser, then that is when it adds multiple entries. Thanks
3:20 pm on July 25, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4988
votes: 12


Then, as I would expect, you are attaching an onclick listener each time. I would move this bit of code to be outside of your feedbacknew function:

$('#fb_submit').click(function () {

var name = $('#fb_uname').val();
var client = $('#fb_client').val();
var department = $('#fb_department').val();
var email = $('#fb_email').val();
var position = $('#fb_position').val();
var feedback = $('#fb_feedbacknew').val();
var data = 'fb_uname=' + name + '&fb_client=' + client + '&fb_department=' + department + '&fb_email=' + email + '&fb_position=' + position + '&fb_feedbacknew=' + feedback;
$.ajax({
type: "POST",
url: "feedback.php",
data: data,
success: function (data) {

$("#feedback").get(0).reset();
$('#fb_message').html(data);

//$("#form").dialog('close');
$("#flex1").flexReload();

},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
return false;

});
5:20 pm on July 25, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 9, 2006
posts:55
votes: 0


@fotiman
that does not work. If I move out of function, it reloads the whole browser without drisplaying the addbox inside the dialog window. I need to keep the results showing in the dialog window. Thanks
5:31 pm on July 25, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4988
votes: 12


Ah, yes, my example would not have worked. Try this instead... add an unbind statement before you set the click handler to remove any previously bound handlers:

$('#fb_submit').unbind('click');
$('#fb_submit').click(function () {
...