greenpool
greenpool

Reputation: 561

AJAX fails only inside JQuery dialog box

How it works

  1. I have a page called displayRecord.php which is loaded inside a JQuery dialog box. The dialog box is created inside editTicket.php

  2. Basically the displayRecord.php allows a user to add a username & ref id and via AJAX $.post it updates the DB and retrieves the number of record in the respective table.

  3. The retrieve counter step is also meant to occur on page load so that not only is it displayed when the user adds the username & password but when the page loads for the first time.

What's failing to work

Step 3 above fails when the displayRecord.php page is inside the JQuery dialog (or atleast thats what I've discovered). If I go to the URL it displays the counter on load. Step 2 still works inside the dialog.

JQuery dialog box call from editTicket.php:

<script type="text/javascript">

var dlg = '';
$(document).ready(function() { 

     dlg=$('#ticketDetails').dialog({
        title: 'TICKET DETAILS',
        resizable: false,
        autoOpen:false,
        modal: true,
        show:'fade',
        hide: 'fade',
        buttons:{ "Close": function() { dlg.dialog("close"); } },
        close: function(e, i) { dlg.hide(); },
        width: 1300   
     });


    $('a.view').click(

        function(e) 
            {    
                dlg.load('displayRecord.php?id='+this.id, function(){ 
                dlg.dialog('open');

            });

        });
});

calling the showCount function on load in displayRecord.php:

<?php if (@$data['escalate'] == "No"){ ?>
        <body onLoad="showCount()">
<?php } else{ ?>
        <body>
    <?php } ?>

showCount function:

function showCount(){

    var ticket_id = <?php echo $data['id']; ?>

    $.post('escalationCount.php',{post_ticket_id:ticket_id}, 
    function(data) {
    $('#escalationCount').html(data);
    });
}

As state before the on page load function doesn't appear to be firing inside the JQuery dialog box.

I'm struggling at this point to identify the source of the problem. Some help please, Thanks.

Upvotes: 0

Views: 348

Answers (1)

Barmar
Barmar

Reputation: 781761

If I understand you correctly (and I'm not sure I do):

$('a.view').click(

    function(e) 
        {    
            dlg.load('displayRecord.php?id='+this.id, function(){ 
                <?php if (@$data['escalate'] == "No") { echo 'showCount();' } ?>
                dlg.dialog('open');

        });

    });

This will update the counter when the dialog is opened.

Upvotes: 1

Related Questions