Welcome to WebmasterWorld Guest from 54.205.60.49

Forum Moderators: open

Message Too Old, No Replies

jquery dialog post being duplicated

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

5+ Year Member



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 Jul 25, 2011 (gmt 0)

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



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 Jul 25, 2011 (gmt 0)

5+ Year Member



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 Jul 25, 2011 (gmt 0)

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



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 Jul 25, 2011 (gmt 0)

5+ Year Member



@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 Jul 25, 2011 (gmt 0)

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



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 () {
...
 

Featured Threads

Hot Threads This Week

Hot Threads This Month