Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is my first question on this site (but the other discussions have helped me).

In the following code:

$('#selObra').change(function() {
      var id_obra = $(this).val();
      if (id_obra == '-1') {
        //Elimino todos los renglones de la tabla
        $('#tblSubcontratos tbody tr').remove();
      } else {
        $('#tblSubcontratos').append('<tr><td class="center" colspan="6"><img src="images/ui-anim_basic_16x16.gif" height="16" width="16" style="margin-left:auto;margin-right:auto" /></td></tr>');
        //Obtengo todos los contratos de la obra seleccionada
        $.ajax({
          type: 'GET',
          dataType: 'xml',
          url: 'get_subcontratos.php',
          data: 'id_obra=' + id_obra,
          success: function(xml) {
            $('#tblSubcontratos tbody tr').remove();
            if ($(xml).find('subcontratos').attr('status') == 'OK') {
              $(xml).find('subcontrato').each(function(){
                var id_subcontrato = $(this).find('id_subcontrato').text();
                var id_obra = $(this).find('id_obra').text();
                var nombre_obra = $(this).find('nombre_obra').text();
                var id_contratista = $(this).find('id_contratista').text();
                var nombre_contratista = $(this).find('nombre_contratista').text();
                var fecha_subcontrato = $(this).find('fecha_subcontrato').text();
                var strRow = '<tr class="ui-widget-content">' +
                               '<td>' + id_subcontrato + '</td>' +
                               '<td>' + nombre_obra + '</td>' +
                               '<td>' + nombre_contratista + '</td>' +
                               '<td>' + fecha_subcontrato + '</td>' +
                               '<td class="center view_details"><img src="images/view.gif" /></td>' +
                               '<td class="center"><input type="radio" name="subcontratoSeleccionado" /></td>' +
                             '</tr>';
                $('#tblSubcontratos tbody').append(strRow);
              });
            } else {
              var errno = $(xml).find('errno').text();
              var error = $(xml).find('error').text();
              $('#message').html(errno + ' - ' + error);
              $('#message').dialog('open');
            }
          }
        });
      }
      $("#divSubcontratos").dialog( "option", "position", 'center' );
    });

Centering the dialog is never executed... I can't see the mistake, the last line that firebug higlights is the bracket to close the else instruction... any comments will be appreciated. Thanks in advance.

Marco.

share|improve this question
 
shouldn't you center it after the ajax response ends (whether successful or failed)? –  Nico May 27 '11 at 0:29
 
Like Nico and RHSeeger told you, try put your dialog call $("#divSubcontratos").dialog( "option", "position", 'center' );, after $('#tblSubcontratos tbody tr').remove(); (Inside the ajax) this should make the magic =) PS: Welcome to Stackoverflow!! PS2: You can use the "Complete" option from ajax to call your dialog, if you want –  Michel May 27 '11 at 1:14
add comment

1 Answer

Two things I note:

  • I see that you're calling dialog on #divSubcontratos, but I don't see that anywhere in the code. I'll assume it already exists at the point the code is being run, but it's worth mentioning
  • As mentioned by Nico, you might want to move the command to center the div into the ajax callback, so you know it's all setup before it runs.
share|improve this answer
 
OK, thanks for all the comments... the case is that I want to center the dialog allways (when the user changes the selected oprion od the drop dwon box) the, that's why the center instruction is at the end, but I'll try to move to the suggested position. Thanks to everybody, this is one of the best sites to learn and to support in programming. BTW... how can I insert code when asking? This is because when I insert the code it was unformatted but someone formatted it for me (thanks!). –  Pispirulito May 27 '11 at 21:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.