My code doesn't really matter, it sends and retrieves the correct info, but the question persists...

How can I verify if the action after my $.ajax call is done and if not perform until done?

Sometimes it performs the action sometimes it doesn't, it loops the request in this case the action:

$('#osa_stocka_'+completo_count+'_'+d).html(rt);

Rest of the code.

var data='id='+$('#osa_stocka_'+completo_count+'_'+d).attr("title");

            var dataString = 'status=checkopapstock&'+ data;

            $.ajax({
                type: "POST",
                url: "components/order/order_processing.php",
                data: dataString,
                success: function(rt){

//alert(rt+' > '+units);

                    if(rt > units){

                        $('#osa_stocka_'+completo_count+'_'+d).html(rt);

                    } else {

                        $('#osa_stocka_'+completo_count+'_'+d).html(rt);
                        $('#property_total_'+completo_count+'_'+d).val(rt);                     

                    }
                }
            });

The simple answer is to put the ajax call inside a function, then add an error handler to the ajax options, like this:

...
error: function() {
	checkopapstock();//try again
}
...

But then you have to consider a number of other things:

  • do you want to limit the number of tries?
  • do you want each ajax request to timeout?
  • what if the user initiates a further request while the ajax is in progress?
  • should all error conditions be handled the same way?

The code gets more complex and will be something like this (untested):

checkopapstock_count = 0;//counter for number of tries
checkopapstock_limit = 10;//number of retries before giving up.
function show_checkopapstock_count() {
	$("#checkopapstock_count").html(checkopapstock_count || '');//optional (to make counter observable)
}

var el = $('#osa_stocka_' + completo_count + '_' + d);

		if(checkopapstock_count > 0) {
			alert('Request is already in progress');//or write the message to the document or to an error logger
			return;
		}
		function checkopapstock() {
			if(++checkopapstock_count > checkopapstock_limit) {//limit number of retries
				checkopapstock_count = 0;//reset the counter
				show_checkopapstock_count();
				return;
			}
			show_checkopapstock_count();//optional (to make counter observable)
			var dataString = 'status=checkopapstock&id=' + el.attr("title");
			$.ajax({
				type: "POST",
				url: "components/order/order_processing.php",
				data: dataString,
				success: function(rt) {
					el.html(rt);
					if(Number(rt) <= units) { $('#property_total_' + completo_count+'_' + d).val(rt); }
					checkopapstock_count = 0;//reset the counter
					show_checkopapstock_count();
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					// textStatus can be "timeout", "error", "notmodified" and "parsererror".
					switch (textStatus) {
						case "timeout":
						case "error":
							checkopapstock();//try again
						break;
						case "notmodified":
						case "parsererror":
							//There's probably no point trying again for these errors as they will just occur again and again.
							checkopapstock_count = 0;//reset the counter
							show_checkopapstock_count();
							alert("checkopapstock error: " + textStatus );//or write the message to the document or to an error logger
						break;
						//NOTE: "notmodified" and "parsererror" alerts are to help debug the server settings and server-side script. They should not occur in final code.
					}
				}
				timeout: 10000 //milliseconds
			});
		}
		checkopapstock(el);//start trying

Airshow

Airshow... WOW!

Was not expecting a so detailed answer, I will test this method you just explained to me. It is a great suggestion of what I haven't thought about.

PS: This happens in this example, but I also experience more or less the same issue when using the jquery.tabs(). It runs the action but doesnt show tabs.

Here follows some pics.
When ok... This also shows the Screenshoot for my first Topic. :D
[IMG]http://www.drosendo.com/tabs.jpg[/IMG]

When not ok:
[IMG]http://www.drosendo.com/tabs1.jpg[/IMG]


I Have tabs inside tabs.
Example:
Outter Tab works 99%

<div id="tabs">
        <ul>
            <li><a href="components/order/view/display_order.php?sid=<?php echo $_SESSION['id_user']; ?>"><?php print(_OM_DISPLAY); ?></a></li>
            <li><a href="components/order/view/add_order.php?sid=<?php echo $_SESSION['id_user']; ?>"><?php print(_OM_ADD); ?></a></li>
        </ul>
    </div>

Using General javascript file:

$("#tabs").tabs().find(".ui-tabs-nav").sortable({
        axis:'x'
    });

Inner TAB 70% "components/order/view/add_order.php"

<div id="tabsi">
        <ul>
            <li><a href="#tabs-info"><?php print(_INFO); ?></a></li>
            <li><a href="#tabs-form"><?php print(_DETAIL); ?></a></li>
            <li><a href="#tabs-products"><?php print(_PRODUCT); ?></a></li>
        </ul>
<div id="tabs-info"></div>
<div id="tabs-form"></div>
<div id="tabs-products"></div>
</div>

Calls this page javascript diffeerent from the above.: $("#tabsi").tabs();

ALFA-FOXTROT,

The INNER tabs are clearly losing their jquery.tabs functionality.

I would have to guess that the INNER tabs that are originally served as part of the page are being overwritten at some stage, probably when page content is delivered.

Make sure that all "Create Order" content is inserted into the divs tabs-info, tabs-form and tabs-products. Similarly make sure that all "Display Orders" content is delivered into a similar structure which does not overwrite the "Create Order" structure.

That's my best guess as to what might be going on. If necessary, try to find a working example of nested jquery.tabs on the internet. It's quite possible that you need to know the right HTML/javascript pattern to get nested tabs to work properly.

Airshow

Worked Perfect!! Thanks

:cool:

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.