Working on a submit function from a jQuery dialog (based on this question). Using codeigniter and jquery.
I’d like to tie the ajax POST to the jquery dialog button click, but don’t know what the selector should be for that button. I tried to use .ui-dialog-buttonpane button:first or “this” as the selector; neither worked.
HTML FORM
<?php echo form_open('bookmarks/addBookmark'); ?> //form name: create_bookmark
<?php echo form_input('bookn', $bname); ?>
<?php echo form_hidden('booki', $this->uri->segment(4, 0)); ?>
<button class="bb_button">Bookmark</button>
<?php echo form_close(); ?>
jQuery
$(function() {
$( "#create_bookmark" ).dialog({
autoOpen: false,
width: 250,
height: 250,
modal: true,
buttons: {
"Add location": function() {
$('?????').click(function() { //How do I specify the dialog button?
$.ajax({
url: '/bookmarks/addBookmark',
type: 'POST',
data:{"bookn": $("input[name='bookn']").val(), "booki": $("[name='booki']").val()},
success: function (result) {
alert("Your bookmark has been added.");
}
});
},
Cancel: function() {$( this ).dialog( "close" );}
}
});
});
The function you specify in the
buttonsobject is the click handler.You can send your request right in that function.