Expected out of order display

0

I'm sending requests, only this return comes in an unexpected order.

I need the update guarantee to come first than support and advice.

It's time to work, there's no time for it.

Unexpected Return

ExpectedReturn

function requisicaoSincrona(categoria, modulo, destino, callback) {
	var xmlhttp = null;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
	}
	var values = {
		modulo: modulo,
		categoria: categoria
	};
	var myJsonString = JSON.stringify(values);
	xmlhttp.onreadystatechange = respond;

	xmlhttp.open('POST', 'classes/getData.php', true);
	xmlhttp.send(myJsonString);
	//xmlhttp.abort();
	//como o código executado na volta da requisição é a função respond, chamamos o callback aqui
	function respond() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			destino.innerHTML += xmlhttp.responseText;
		}
		//verifica se uma função foi de fato passada, para então chama-la
		if (callback) callback.call();
	}
}
var x = document.getElementsByClassName('terceiraEtapa')[0];
requisicaoSincrona(6, modulo, x, function() {
	requisicaoSincrona(9, modulo, x);
});
    
asked by anonymous 27.09.2017 / 16:55

1 answer

0

I think your problem is just the asynchronous request, which is the default for browsers. Explanation

If I change the third entry of the next line of code to FALSE, I believe I will always get the expected result, but I do not say it is the best solution.

xmlhttp.open('POST', 'classes/getData.php', true);

I would try to return both HTML structures in the same request to the getData.php file.

    
02.10.2017 / 14:52