473,408 Members | 2,444 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,408 software developers and data experts.

How to bind a jquery ui dialogue function after recieving a response from ajax call?

245 100+
Hi Experts,
I have create a jQuery ui function which delete product from the shopping list. After receiving a jQuery Ajax response i want to bind the same function which load on page load. How can i bind the same function after receiving the Response.
Here is my JavaScript Code

Expand|Select|Wrap|Line Numbers
  1. $( ".rData" ).click(function() {
  2.                     $( "#dialog-confirm:ui-dialog" ).dialog( "destroy" );
  3.                     myLink = $(this).attr("href");
  4.                     $.urlParam = function(name){
  5.                         var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(myLink);
  6.                         if (!results) { return 0; }
  7.                         return results[1] || 0;
  8.                     }
  9.                     var list_id = $.urlParam('list_id');
  10.                     var prod_id = $.urlParam('prod_id');
  11.                     $( "#dialog-confirm" ).dialog({
  12.                         autoOpen: false,
  13.                         resizable: false,
  14.                         width:400,
  15.                         height:170,
  16.                         modal: true,
  17.                         buttons: [{
  18.                             text: "Yes",
  19.                             click: function() {
  20.                                 $('#listUpdateMsg').html('<img src="images/redloading.gif" title="Updating List...." /> Updating List...');
  21.                                 $.ajax({
  22.                                     data: "sid="+Math.random()+"&act=remove&list_id="+list_id+"&prod_id="+prod_id,
  23.                                     url: "ajax/add_to_shooping_list.php",    
  24.                                     type:"POST",
  25.                                     success:function(msg){
  26.                                         var $msgarray = msg.split("|");
  27.                                         $('#listUpdateMsg').html('<div><div class="err"><span class="ui-icon ui-icon-alert" style="float:left; margin:0 0 0 15px;"></span>'+$msgarray[0]+'</div><br />'+$msgarray[1]+'</div>');
  28.                                         $( "#dialog-confirm:ui-dialog" ).dialog( "destroy" );
  29.                                     }
  30.                                 });
  31.                             }
  32.                         },{
  33.                             text: "No",
  34.                             click: function() { $(this).dialog("close"); }
  35.                         }
  36.                     ] });
  37.                     $( "#dialog-confirm" ).dialog( "open" );
  38.                     return false;
  39.                 });

This is the area where i am receiving response
Expand|Select|Wrap|Line Numbers
  1. success:function(msg){
  2.                                         var $msgarray = msg.split("|");
  3.                                         $('#listUpdateMsg').html('<div><div class="err"><span class="ui-icon ui-icon-alert" style="float:left; margin:0 0 0 15px;"></span>'+$msgarray[0]+'</div><br />'+$msgarray[1]+'</div>');
  4.                                         $( "#dialog-confirm:ui-dialog" ).dialog( "destroy" );
  5.                                     }
Now here i want to bind the same function how can i do that?

Kindly help me out to sort out my problem i will be very grateful to experts.
Mar 7 '11 #1
3 9574
acoder
16,027 Expert Mod 8TB
If I'm following correctly, maybe this is what you're looking for.
Mar 7 '11 #2
neovantage
245 100+
Sorry...! that is not relevant to my problem.

Let me explain it in more detail.

When first time page is loaded i attached a dialog confirmation Box. Which asked either you want to remove the selected product or not. If it says yes then a ajax base request is submitted and give response which populate a section having html tags and some dynamic code. In response there is an anchor tag which has a class .rData but at this time it is not initialized with jQuery Ui Dialog Box. So when i again try to remove another product from the shopping list list without refreshing the whole page it does not open the dialog box again. Instead it submit the whole page which i don't want to. I want it open the same dialog box again and ask either i want to remove the product or not. If yes then again it send a ajax request and give response. @nd time my .rData class is not re-initialized which does not open the dialog box. So what i want when a response is return dialog box is again initialized the way it first time initialized on page load.
Mar 7 '11 #3
neovantage
245 100+
I have got the solutions guys.
Here is the solution of my problem may be that is helpful for the others.

Expand|Select|Wrap|Line Numbers
  1. $(function(){ 
  2. RemoveProductTrigger();
  3. });
  4. function RemoveProductTrigger(){
  5.                 $( ".rData" ).click(function() {
  6.                     $( "#dialog-confirm:ui-dialog" ).dialog( "destroy" );
  7.                     myLink = $(this).attr("href");
  8.                     $.urlParam = function(name){
  9.                         var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(myLink);
  10.                         if (!results) { return 0; }
  11.                         return results[1] || 0;
  12.                     }
  13.                     var list_id = $.urlParam('list_id');
  14.                     var prod_id = $.urlParam('prod_id');
  15.                     var ctl = $.urlParam('ctl');
  16.                     if(ctl!="list_operations"){
  17.                         $( "#dialog-confirm" ).dialog({
  18.                             autoOpen: false,
  19.                             resizable: false,
  20.                             width:400,
  21.                             height:170,
  22.                             modal: true,
  23.                             buttons: [{
  24.                                 text: "Yes",
  25.                                 click: function() {
  26.                                     $('#listUpdateMsg').html('<img src="images/redloading.gif" style="padding-left:15px;" title="Updating List...." /> Updating List...');
  27.                                     $.ajax({
  28.                                         data: "sid="+Math.random()+"&act=remove&list_id="+list_id+"&prod_id="+prod_id,
  29.                                         url: "ajax/add_to_shooping_list.php",    
  30.                                         type:"POST",
  31.                                         success:function(msg){
  32.                                             var $msgarray = msg.split("|");
  33.                                             $('#listUpdateMsg').html('<div><div class="err"><span class="ui-icon ui-icon-check" style="float:left; margin:0 0 0 15px;"></span>'+$msgarray[0]+'</div><br />'+$msgarray[1]+'</div>');
  34.                                             $( "#dialog-confirm" ).dialog( "close" );
  35.                                             RemoveProductTrigger();
  36.                                             ProductDetail();
  37.                                         }
  38.                                     });
  39.                                 }
  40.                             },{
  41.                                 text: "No",
  42.                                 click: function() { $(this).dialog("close"); }
  43.                             }
  44.                         ] });
  45.                         $( "#dialog-confirm" ).dialog( "open" );
  46.                         return false;
  47.                     }
  48.                 });
  49.             }
  50.  
Mar 9 '11 #4

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

Similar topics

13
by: Russell Hind | last post by:
I'm trying to use boost::bind and boost::function inside managed code, but there appears to be some code generation problems. The following code compiles fine, but the function object throws an...
1
by: Grzegorz Smith | last post by:
Hi everyone. Does anyone know is it possible to check if ajax call was redirect? i mean I connect by Ajax to one URL but I'm redirected to other url. Is there a way to check that my request was...
2
by: Zeba | last post by:
Hi guys! I'm new to JS / Ajax; I've been trying to do an Ajax call to my Webservice ( I'm using C# for code-behind). I'm not using any of the libraries available. I am sending my CustID to the...
3
by: nghivo | last post by:
I attempted to synchronize async Ajax calls using the following JS blocks: ==================================================== function getXMLHTTPRequest() { try { req =...
3
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes...
4
by: dmorand | last post by:
I'm curious as to how you all pass data back to the calling page when using AJAX. I have a button on a page which when clicked calls a coldfusion page to perform a query to retrieve some employee...
10
dmjpro
by: dmjpro | last post by:
function synchronous_ajax(){ var ajax = null; if(typeof ActiveXObject!='undefined') ajax = new ActiveXObject("Microsoft.XMLHTTP"); else if(typeof XMLHttpRequest!='undefined') ajax = new...
5
RamananKalirajan
by: RamananKalirajan | last post by:
Hi guys, I am having a problem in Prototypejs AJAX, I am triggering the AJAX call and in the option i am using like the folowing code: new Ajax.Request(connection.url, { method:...
3
by: rbansalit | last post by:
Hi all I am making a very simple ajax call. But I am not getting any message from sever. <html> <body> <script type="text/javascript"> function ajaxFunction()
5
oranoos3000
by: oranoos3000 | last post by:
hi i read about bind jqeury method general syntax as follow as bind(eventType,data,listener) Establishes a function as the event handler for the specified event type on all elements in...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.