0

我有一个标准设置。我有一个提供数据的 php 页面。数据中有一些编辑链接。我的问题是,在我编辑一些数据后,第二次单击编辑链接时,我的 JQuery-UI 会在传递给它的 url 上打开,而不是填充 JQuery-UI.dialog。

基本页面 Java (view.php)

   var editParyAddress = $('#edit_party_address').dialog({
      autoOpen: false,
      width:'auto',
      modal: true,
      buttons: {
        'Save': function(){
          $.ajax({
            url: '/party_address/save.php',
            type: 'POST',
            data: $('#edit_party_address_form').serialize(),
            success: function(data){
              $.get('helper.php?function=partyaddress&id=<?php echo $_GET['id'];?>',function(data){$('#partyaddress').html(data);});
              //$('#edit_party_address').dialog('close');
              $('#edit_party_address').dialog("destroy").remove();
            }
          });
        }
      }
    });

    $('.edit_party_address').click(function(e){
      e.preventDefault();
      $.ajax({
        url: $(this).attr('href'),
        type: 'POST',
        success: function(data){
          editParyAddress.html(data);
          editParyAddress.dialog('open');
          return false;
        }
      });
    });

将数据提供给 JQuery-UI.dailog (edit.php) 的 PHP 页面

$sql="SELECT dbo.format_full_name(p.first_name,p.middle_name,p.last_name) name, dp.party_id, pa.id partyaddressid, pa.address1,pa.address2,pa.city,pa.state,pa.zip_code,pa.address_indicator_id,pa.is_active
FROM [".DB1."].[DBO].[party_address] pa
INNER JOIN debt_party dp on dp.party_id=pa.party_id
INNER JOIN party p on p.id=pa.party_id
where pa.id=".$_GET['party_address_id'];
$HTML='';
$conn =db_connect();
$stmt = sqlsrv_query($conn, $sql,array(),array( "Scrollable" => 'keyset' ));
if( $stmt === false) { error($_SERVER['PHP_SELF'],__FUNCTION__,__LINE__);return;}

$HTML= '<form name="edit_party_address_form" id="edit_party_address_form" style="width:100%" action="">';
if ($stmt===false) {return;}
if (sqlsrv_has_rows( $stmt )=== false){return;}
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC);
$HTML.='<fieldset>';
$HTML.='<ol>';
$HTML.='<li><label for="address_address1">Address 1:</label><input class="text-input" id="address1" name="address1" size="30" type="text" value="'.$row['address1'].'"></li>';
$HTML.='<li><label for="address_address2">Address 2:</label><input class="text-input" id="address2" name="address2" size="30" type="text" value="'.$row['address2'].'"></li>';
$HTML.='<li><label for="address_city">City:</label><input class="address" id="address_city" name="address_city" size="30" type="text" value="'.$row['city'].'"></li>';
$HTML.='<li><label for="address_state">State:</label><input class="state" id="address_state" name="address_state" maxlength="2" size="2" type="text" value="'.$row['state'].'"></li>';
$HTML.='<li><label for="address_zip_code">Zip Code:</label><input class="zip_code" id="address_zip_code" maxlength="10" name="address_zip_code" size="10" type="text" value="'.$row['zip_code'].'"></li>';
$HTML.='<li><label for="name">Indicator:</label>'.HTMLOptions(DB1,'dbo','address_indicator','id','name',$row['address_indicator_id']).'</li>';
$HTML.='<li><label for="is_active">Active:</label><input '.($row['is_active']==1? ' checked="checked"':'').' name="is_active" maxlength="2" size="2" type="checkbox" value="'.$row['is_active'].'"></li>';
$HTML.='<li><input id="party_address_id" name="party_address_id" type="hidden" value="'.$_GET['party_address_id'].'"></li>';
$HTML.='</ol>';

$HTML.='</fieldset>';
$HTML.='</form>';
sqlsrv_free_stmt( $stmt);
echo $HTML;

PHP 保存页面 (save.php)

$sql="UPDATE party_address SET address1='".$_POST['address1']."',address2='".$_POST['address2']."'  WHERE id=".$_POST['party_address_id'];   

    $conn =db_connect();
    $stmt = sqlsrv_query($conn, $sql,array(),array( "Scrollable" => 'keyset' ));
    if( $stmt === false) { error($_SERVER['PHP_SELF'],__FUNCTION__,__LINE__);return;}
    sqlsrv_free_stmt( $stmt);

当我单击如下所示的编辑链接时:/party_address/edit.php?party_address_id=1468941一切正常。一旦我提交了发布的表单更改,它就会更新数据库和 view.php 基本页面。提交更改后,第二次单击任何编辑链接时,该链接使用默认行为,浏览器地址更改为编辑链接。这只是显示了我的 view.php 页面的内部 HTML。它应该在 JQuery-UI.dialog 中打开<div id="edit_party_address" title="Edit Party Address"></div>

4

1 回答 1

0

我在我的 Base Page Java (view.php)中更改了两行, 为了清楚起见,我只是将它们留在这里评论。现在可以了!!!

var editParyAddress = $('#edit_party_address').dialog({
  autoOpen: false,  width:'auto',  modal: true,
  buttons: {
    'Save': function(){
      $.ajax({
        url: '/party_address/save.php',
        type: 'POST',
        data: $('#edit_party_address_form').serialize(),

        success: function(data){
          alert(data);
          $.get('helper.php?function=partyaddress&id=<?php echo $_GET['id'];?>',function(data){$('#partyaddress').html(data);});
          $('#edit_party_address').dialog('close');
          //$('#edit_party_address').dialog("destroy").remove();
        }
      });
    }
  }
});
// $('.edit_party_address').click(function(e){
$(document).on('click', '.edit_party_address', function (e) {
    e.preventDefault();
    $.ajax({
    url: $(this).attr('href'),
    type: 'POST',
    success: function(data){
      editParyAddress.html(data);
      editParyAddress.dialog('open');
      return false;
    }
  });
});
于 2013-02-28T17:22:19.523 回答