Hi, Daniel.

 

If I understand what you're doing, then yes, you can run an ajax request
inside the response section

of another ajax request.I do it all the time.

 

Here's some code from one of my sites that does that very thing (there's
some ColdFusion in there, too):

 

$.ajax ({   cache:          false,

            url:
'../components/successStoriesManager.cfc?method=mUpdateStoryOrder&returnForm
at=json',

            type:           "post",

            dataType:       "json",

            data:           datavalues,

            success:        function(response) {

                                                              

                                 if     (     response.MESSAGE == 'Success'
)

 


                                              datavalues =  {   dsn:
'<cfoutput>#application.dsn#</cfoutput>',

                                                                orderBy:
'story_order'  };

                     

                                              $.ajax        ({  cache:
false,

                                                                type:
"post",

                                                                url:
"../components/successStoriesManager.cfc?method=mGetAllStories&returnFormat=
json",

                                                                dataType:
"json",

                                                                data:
datavalues,

                                                                success:
function(response) {

                                                       

 
if      (   response.MESSAGE == 'Success'       )

 
{   populateStoryTable(response);       }

 


 
else   {    alert('Rats!  It did not work!');  }

 


                                                                           }

                                              });

                                                                           

                            }

                                                                     

});

 

 

The full function is before the first ajax call above is a bunch of
functionality irrelevant to the ajax part.

But this should give you an idea of how to structure your code for an ajax
call within the success section of the first ajax call.

 

hth,

 

Rick

 

From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of Daniel Israel
Sent: Friday, July 31, 2009 6:23 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Ajax sometimes not executing callback...

 

 

OK....  I hope people will forgive my faux pas of responding to my own
item...

 

so I have found my problem.  It turns out that the "this" in the line:
$(this).dialog('close');

 

is not referring to the dialog...  but to the ajax request.  Duh.

 

There are a couple other things too...  but I was wondering about this:

 

When I get the return from the ajax request, I want to call another function
that calls an ajax request.  Seems that things get kinda messed up.   I have
fixed it by setting a timeout to call that function.

 

Are embedded Ajax calls not supported?

 

Thanks.

 

 

On Jul 31, 2009, at 1:40 PM, Daniel Israel wrote:





 

I'm using jQuery and jQueryUI.  I'm new to jQuery, so any help much
appreciated...

 

I have an application where I am displaying a list from a database.  When
the user hits a button, a modal form dialog comes up and they can enter
data.

 

It makes an ajax call to the server, gets the data, populates the dialog,
then opens it.  Change the data, hit the "Create" button and it makes
another Ajax call to update the database.

 

I see the changes (correctly) in the database, but the callback is not being
executed!  It's the weirdest thing...  I'm not sure what the problem is..  I
examine the HTTP traffic and I'm getting a status of 200 and the response
looks correct.

 

If it matters, I'm on OS X using FF 3.51

 

Note that if I put an alert before the dialog('close') call, the alert pops
up, but the dialog does not close... :(

 

Code for this dialog is here:

 

                        $("#dialog").dialog({

                                    bgiframe: true,

                                    autoOpen: false,

                                    height: 350,

                                    modal: true,

                                    buttons: {

                                                'Create': function() {

                                                            var data = {
section: $("#section_id").val(), label: $("#label").val(), description:
$("#description").val(), thumbnail: $("#thumbnail").val(), format:
$("#format").val() };

 
$.post("command/save_section.php", data, function(xml) {

                                                                        var
save_request = parseInt($("#section_id").val());

                                                                        var
save_result = parseInt($('section', xml).text());

 
//alert("testing " + save_request + " to " + save_result);

                                                                        if
(save_request == save_result) {

 
$(this).dialog('close');

                                                                        }

                                                                        else
{

 
open_alert_dialog("There was an error when processing this request!");

                                                                        }

                                                            });

                                                },

                                                Cancel: function() {

 
$(this).dialog('close');

                                                }

                                    },

                                    close: function() {

 
allFields.val('').removeClass('ui-state-error');

                                    }

                        });

 

 

 

any help is appreciated... thanks.

 

 

-D. Israel
d...@ebji.org
http://www.customcodebydan.com <http://www.customcodebydan.com/> 
AIM: JudoDanIzz

 

If a dozen smart, successful people who've achieved something great are all
giving the same advice, take it.

 

 

-D. Israel
d...@ebji.org
http://www.customcodebydan.com <http://www.customcodebydan.com/> 
AIM: JudoDanIzz

 

If a dozen smart, successful people who've achieved something great are all
giving the same advice, take it.

 

Reply via email to