简体   繁体   中英

JQuery Dialog box content cleared after open

I have this code that is to open a dialog box with content generated from a php class only problem is that within 2sec the code gets clear from the dialog box. Here is the JavaScript/JQuery:

$k('#CreateTable').click(function(e){
        e.preventDefault();
         var Call =  $k('#CreateTable').attr('value');
         var util = $k(this).attr('id');//.attr('value');
        // alert(util);
         $k('#dialog').dialog({
             autoOpen: false,
            title: 'Running Utility for: '+Call,
            modal: true,
            width: 450,
            close: function(event, ui) {
            $k("#dialog").empty(); // remove the content
            }//END CLOSE
        }).dialog('open');
        $k.ajax({
                  type: "post",
                  url: "inc/runUtilities.php",
                  dataType: "html",
                  data: {
                    'utility' : util
                  },
                  success: function(data) {
                        //alert('success'); 
                        $k('#DlgTxt').html(data).fadeIn('slow');
                  }
        });
            //return false;
        });//END DIALOG

It gets triggered from the following button code:

<div class="tab-pane fade in active" id="Utilities">
          <p>
          <div>
            <button class="btn btn-lg btn-default" type="button" 
 value="Create Table" id="CreateTable" >Create Table</button>
          </p>
          </div>
       </div>

Is there something i am missing?

Simply remove the ".k" will do: $.k() to $()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>

<script type="text/javascript">
$(function() {
    $('#CreateTable').click(function(e){
        e.preventDefault();
         var Call =  $('#CreateTable').attr('value');
         var util = $(this).attr('id');//.attr('value');
        // alert(util);
         $('#dialog').dialog({
            autoOpen: false,
            title: 'Running Utility for: '+Call,
            modal: true,
            width: 450,
            close: function(event, ui) {
            $("#dialog").empty(); // remove the content
            }//END CLOSE
        }).dialog('open');
        $.ajax({
                  type: "post",
                  url: "YOUR URL HERE",
                  dataType: "html",
                  data: {
                    'utility' : util
                  },
                  success: function(data) {
                        //alert('success'); 
                        $('#DlgTxt').html(data).fadeIn('slow');
                  }
        });
            //return false;
        });//END DIALOG
});
</script>
</head>

<body>
<div class="tab-pane fade in active" id="Utilities">
          <p>
          <div>
            <button class="btn btn-lg btn-default" type="button" 
 value="Create Table" id="CreateTable" >Create Table</button>
          </p>
          </div>
       </div>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM