473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to prevent page refresh based on ajax results and dialog boxes

129 100+
Hi

I am trying to create a display of files / documents with the abilities to view and delete. I use jquery ui dialogs and ajax to delete the certain files (which works) However everytime the results are refreshed with the new data, when you click the next file to delete it does a page refresh and then works. Can someone please tell me how to prevent this from happening?

Here is my code;

First the javascript

Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>
  2. $(document).ready(function()
  3. {
  4.     $.fx.speeds._default = 1000;
  5.     $('a.confirmLink').bind('click',function(e)
  6.     {
  7.         var btnPrefix = 'confirmLink_';
  8.         var docNum = $(this).attr('id').substring((btnPrefix.length));
  9.         e.preventDefault();
  10.         $('#dialog_' + docNum)
  11.             .data('docNum', docNum)
  12.             .dialog('open');
  13.  
  14.     });
  15.  
  16.     $( '[id^=dialog_]' ).dialog( 
  17.     {
  18.         autoOpen: false,
  19.         closeOnEscape: true,
  20.         open: function(event, ui) { $('.ui-dialog-titlebar-close').hide(); },
  21.         draggable: false,
  22.         resizable: false,
  23.         position: 'center',
  24.         show: {effect: 'drop', direction: 'up'},
  25.         hide: {effect: 'drop', direction: 'down'},
  26.         width: 360,
  27.         modal: true,
  28.         overlay: {
  29.             backgroundColor: '#000',
  30.             opacity: 0.8
  31.         },
  32.         buttons: 
  33.         {
  34.             'Confirm': function()
  35.             {
  36.                 $( this ).dialog( 'close' );
  37.                 var docNum = $(this).data('docNum');
  38.                 var dataString = {'diaryID' : '".$diaryID."','docID' : docNum};
  39.                 $.ajax(
  40.                 {
  41.                     type: 'POST',
  42.                     url: '".AJAX."updateDocumentList.php',
  43.                     data: dataString,
  44.                     cache: false,
  45.                     success: function(data) 
  46.                     {
  47.                         $('.document-list').html(data)
  48.                     }
  49.                 });
  50.             },
  51.             Cancel: function()
  52.             {
  53.                 $( this ).dialog( 'close' );
  54.             }
  55.         }
  56.     });
  57. });
  58. </script>
Then the HTML

Expand|Select|Wrap|Line Numbers
  1. <div class="document-list">';
  2.     if($this->getData('documentList'))
  3.     {
  4.         $content .= '
  5.         <ul class="thumbnail-images">';
  6.         foreach($this->getData('documentList') as $dbDocument)
  7.         {
  8.             $baseFileName = preg_replace('/(.*)\.([^.]+)$/','\\1',$dbDocument['documentName']);
  9.             $extension = substr($dbDocument['documentName'], strrpos($dbDocument['documentName'], ".") + 1);
  10.             $docThumbName = $baseFileName.'_thumb.'.$extension;
  11.             $docMediumName = $baseFileName.'_medium.'.$extension;
  12.             $content .= '
  13.             <li>
  14.                 <a href="'.FILE_UPLOADS.$dbDocument['documentPath'].'/'.$dbDocument['revisionPath'].'/'.$docMediumName.'"><img src="'.FILE_UPLOADS.$dbDocument['documentPath'].'/'.$dbDocument['revisionPath'].'/'.$docThumbName.'" alt="'.$dbDocument['description'].'" /></a>
  15.                 <a id="confirmLink_'.$dbDocument['documentID'].'" class="confirmLink" href=""><img class="delete" src="'.ICON_IMAGES.'ico_cross.png" alt="Delete Image" /></a>
  16.                 <div id="dialog_'.$dbDocument['documentID'].'" title="<h2>Delete Confirmation</h2>">
  17.                     <p>Are you sure you want to remove "'.$dbDocument['documentName'].'" from the system?</p>
  18.                     <p class="bold">Image Preview:</p>
  19.                     <img src="'.FILE_UPLOADS.$dbDocument['documentPath'].'/'.$dbDocument['revisionPath'].'/'.$docThumbName.'" alt="'.$dbDocument['description'].'" />
  20.                 </div>
  21.             </li>';
  22.         }
  23.         $content .= '
  24.         </ul>';
  25.     }
  26.     else
  27.     {
  28.         $content .= '
  29.         <p class="no-evidence">No evidence has been added / uploaded to this daily diary</p>';
  30.     }
  31. $content .= '
  32. </div>
I have tried numerous attempts with using return false and e.preventDefault(), i have tried replacing the a tag to just using img and yet still the same problem of page refreshing.

Any help would be greatly appreciated!
Jun 15 '11 #1
5 2682
Constantine AI
129 100+
Does anyone have any ideas with this post? I have tried many attempts to solve this issue and nothing has solved it!
Jul 6 '11 #2
Constantine AI
129 100+
I have come back to this issue and still haven't found a solution. If anyone can help it will be hugely appreciated!
Dec 22 '11 #3
Constantine AI
129 100+
Here is the ajax code:

Expand|Select|Wrap|Line Numbers
  1.     if(isset($_REQUEST['docID']))
  2.     {
  3.         $docID = $_REQUEST['docID'];
  4.     }
  5.     else
  6.     {
  7.         $docID = '';
  8.     }
  9.  
  10.     if(isset($_REQUEST['diaryID']))
  11.     {
  12.         $diaryID = $_REQUEST['diaryID'];
  13.     }
  14.     else
  15.     {
  16.         $diaryID = '';
  17.     }
  18.  
  19.     $Document = new Document();    
  20.  
  21.     if($docID)
  22.     {
  23.         $Document->deleteDocument($docID);
  24.     }
  25.     $documentList = $Document->getDocumentsByDiary($diaryID);
  26.  
  27.     if($documentList)
  28.     {
  29.         echo '
  30.         <ul class="thumbnail-images">';
  31.         foreach($documentList as $dbDocument)
  32.         {
  33.             $baseFileName = preg_replace('/(.*)\.([^.]+)$/','\\1',$dbDocument['documentName']);
  34.             $extension = substr($dbDocument['documentName'], strrpos($dbDocument['documentName'], '.') + 1);
  35.             $docThumbName = $baseFileName.'_thumb.'.$extension;
  36.             $docMediumName = $baseFileName.'_medium.'.$extension;
  37.             if($extension == 'jpg' || $extension == 'gif' || $extension == 'png')
  38.             {
  39.                 echo '
  40.                 <li>
  41.                     <a href="'.FILE_UPLOADS.$dbDocument['documentPath'].'/'.$dbDocument['revisionPath'].'/'.$docMediumName.'"><img src="'.FILE_UPLOADS.$dbDocument['documentPath'].'/'.$dbDocument['revisionPath'].'/'.$docThumbName.'" alt="'.$dbDocument['description'].'" /></a>
  42.                     <a id="confirmLink_'.$dbDocument['documentID'].'" class="confirmLink" href=""><img class="delete" src="'.ICON_IMAGES.'ico_cross.png" alt="delete document" /></a>
  43.                     <div id="dialog_'.$dbDocument['documentID'].'" title="<h2>Delete Confirmation</h2>" style="display:none;">
  44.                         <p>Are you sure you want to remove "'.$dbDocument['documentName'].'"?</p>
  45.                         <p>Image Preview:</p>
  46.                         <img src="'.FILE_UPLOADS.$dbDocument['documentPath'].'/'.$dbDocument['revisionPath'].'/'.$docThumbName.'" alt="'.$dbDocument['description'].'" />
  47.                     </div>
  48.                 </li>';
  49.             }
  50.         }
  51.         echo '
  52.         </ul>';
  53.     }
  54.     else
  55.     {
  56.         echo '
  57.         <p>No evidence has been added / uploaded to this daily diary</p>';
  58.     }
Dec 22 '11 #4
Dormilich
8,658 Expert Mod 8TB
your AJAX URL looks strange, are you sure ".AJAX."updateDocumentList.php is correct?
Dec 23 '11 #5
Constantine AI
129 100+
Expand|Select|Wrap|Line Numbers
  1. define('AJAX',                            SITE_URL.'library/ajax/');
Yeah the url is correct. It does post to the AJAX script, processes the info and returns to the div. Thanks for taking a look by the way!
Dec 23 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: lucas | last post by:
Hi, I have a simple input form that i use to add records to a sql server database. Bellow that is a datagrid that has one template column that I use to dispaly the 3 fields with some html...
3
by: Matt | last post by:
Is there a way to execute server code without doing a complete page refresh in .Net? I have an ASP page to convert that uses XMLHTTP and I'm wondering if I should continue to use it in ASPX or do...
9
by: PK9 | last post by:
I'm having an issue with the "Refresh" of an asp.net page. The refresh is actually calling my last onClick event. I thought that asp.net was supposed to be stateless in that it shouldn't...
5
by: seanmle | last post by:
Is it possible if I can call server side code without the page refreshing? Thanks, Sean
9
by: preetksaini | last post by:
hi i am having a page in which i have 3 dropdowns,values of 2nd dropdown comes based on 1st and values of 3rd dropdown come based on 2nd.using AJAX+PHP to load dropdowns. but whenever i refresh...
4
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. If an ASP.NET page postsback, for example, after a button is clicked, and then I refresh the page (ie, by pressing F5 key), why does the same event occur when I press F5 as it did when I...
1
by: NoNameNoWhere | last post by:
I have forms that are handled by PHP scripts in the same file that generates the page. After the page regenerates with the results of the form submission, a refresh of the page re-submits the...
2
by: one.1more | last post by:
I want to make a text game using javascript dialog boxes. i learned about confirm boxes but its not helpful(http:// www.javascriptmall.com/learn/lesson6.htm) 1. for ex, in the confirm boxes,...
3
chathura86
by: chathura86 | last post by:
hi im building a site using ASP.NET 2.0 with AJAX Created a new site (AJAX Enabled site) I have added a update panel and some controls in to it it worked fine at the beginning but as i...
2
by: athar258 | last post by:
hi all, I am developing a web application related to the share market, what i want to accomplish is that i want to present the user share market data that will be updated every 40 seconds. but i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.