stupidajax: function()
    {


        var varpas=$j('#somediv',window.parent.document).text();
        varpas.replace(/\s/g, "");


        $j.ajax({  // Start AJAX function                                     
            url: 'mysqlcall.php',                  //script      
            async: false,
            data: "parameter1="+varpas,                        //you can insert url argumnets here to pass to api.php
                                            //for example "id=5&parent=6"
            dataType: 'json',                //data format      

                            success: function(data)          //on recieve of reply
                                { //start success function


                               var selecthtml='Things: <select name="d" id="d">'

                                    for (var i=0;i<data.length;i++)
                                        {    //start for  

                                            var r = data[i];          
                                            var n = r[0]; 


                                            var c = r[1]; 

                                            if (i==0)
                                            {
                                                selecthtml=selecthtml+'<option value="'+c+' selected="selected">'+n+'</option>';
                                            }
                                            else
                                            {
                                                selecthtml=selecthtml+'<option value="'+c+'>'+n+'</option>';
                                            }




                                        }  //end for

                                        selecthtml=selecthtml+'<option value="Default">Default</option>';
                                        selecthtml=selecthtml+'</select>';



                                        } //end success

                                        complete: function(data)
                                        {
                                            alert("hi"); // <----line that pisses me off
                                        }




                    }); //end ajax function


    },

Im trying to print that hi alert AFTER I load up the combobox but it always comes out first. I thought the complete function was able to do that but it does not do it. What is the best way to print it out?

I want to say that I dont want to just print out a alert, I want to do something else but once I get that alert out there, I can move on to something more complicated (the image loading)

Thank you

Shouldn't there be a comma separating success and complete?

Shouldn't there be a comma separating success and complete?

Make absolutly no difference at all. With or without comma, the code does the same thing (tested)

Which jquery version are you using? The newer way would be to use the chained events .done, .fail and .always

Im using 1.8.3

How would I use those chained events you commented in the code Ive written?

Member Avatar for stbuchok

What do you get with just this? What order are the alerts called in? Also what are you doing with selecthtml as it isn't doing anything except filling the variable. Also, selecthtml is not available outside the success function.

$j.ajax({
            url: 'mysqlcall.php',
            async: false,
            data: "parameter1="+varpas,
            dataType: 'json',
            success: function(data) {
                alert('success');
            },
            complete: function(data) {
                alert('complete');
            }
});

Yup, complete is declared just like that but does not work.

I thought the code explained itself, sorry. I get values from a MySQL database and with it make a combobox. From there I want to select the first value THEN that first value (lets say its "Heart") has a image on the server ("Heart.jpg") which it should load. But, since that complicated, I want to show a simple alert first.

The code I posted is a snippet. It works but I cant get the rest to work (show a simple alert)

$j.ajax({
    url: 'mysqlcall.php',
    async: false,
    data: { parameter1: varpas },
    dataType: 'json'
})
.done(function () { alert('done'); })
.fail(function () { alert('fail'); })
.always(function () { alert('always'); })

Please use my code :) You removed a ";" and Im not sure where it goes or if it changes anything.

Member Avatar for stbuchok

You say it is declared the same way, however it is not. Like pritaes has said you are missing a comma before complete.
Did you actually try running my code and see which one gets fired first? We are trying to help and you are not doing the things we are asking which makes it hard to figure out what you are doing wrong.
Are there any errors that come up in the dev toolbar (for which ever browser you are testing in)? Also, again selecthtml variable is being set but not used so it's not going to do anything.

You say it is declared the same way, however it is not. Like pritaes has said you are missing a comma before complete.
Did you actually try running my code and see which one gets fired first? We are trying to help and you are not doing the things we are asking which makes it hard to figure out what you are doing wrong.
Are there any errors that come up in the dev toolbar (for which ever browser you are testing in)? Also, again selecthtml variable is being set but not used so it's not going to do anything.

Yup, I ran the code with and without the comma. No error.

Yes, I ran the code and I see that the alert when using the done or complete function fires first before the ajax code (which for testing purposes, I also put a alert)

No errors coming up (Firefox/Firebug). Ignore the selecthtml variable as it is not the point for now in this case.

Thank you for the help :)

Member Avatar for stbuchok

Just out of curiousity, why do you need complete? why not just call a function at the end of the success?

Just out of curiousity, why do you need complete? why not just call a function at the end of the success?

Because I need to be sure that it runs after success and I believe it doesnt do that if I just put code after the end of success...

Still trying ideas but it doesnt work.

Member Avatar for stbuchok

what I mean is, why not just put code in the success function after the rest of the code?

what I mean is, why not just put code in the success function after the rest of the code?

Well because (this is personal thought), I need it to correct do the AJAX function. The AJAX function/page connects to a MySQL database. If it fails the connection, it shouldnt do this code.....

I may be wrong but...

Member Avatar for stbuchok

can you put this online so that we can see the page and fiddle around with it, this is going nowhere.

Member Avatar for stbuchok

that last comment sounds harsh, so let me clarify by saying that it is hard to help if I can't see what is going on.

can you put this online so that we can see the page and fiddle around with it, this is going nowhere.

that last comment sounds harsh, so let me clarify by saying that it is hard to help if I can't see what is going on.

Online there is only old code. Im working on this new code on my development box so it isnt online. Port 80 is problably blocked by my ISP so I cant host my development box online...

Ive been trying with DDNS to put my dev machine online but cant, sorry.

Member Avatar for stbuchok

You can always create a demo page and put that online.

You can always create a demo page and put that online.

Complicated: The combo is populated from a store website. The only thing I can think of is to make a demo page with what I populate from the store website hardcoded.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.