Reload with Jquery without cache (Chrome)

0

I do not really know if the problem is the cache or the script I made or the server I'm using, but come on.

I am using this code to upload a document to the server (I have not yet evaluated security and performance issues).

if($("#add-doc").isValid()){

$.ajax({
    url: 'api/upload-doc.php',
	type: 'POST',
	data: formData,
	beforeSend: function(){

		$("#docs-objeto3 #forms").hide();
		$("#docs-objeto3 #loader-bar").show().fadeIn('slow');

	},
	success: function (data) {
		console.log(data);
	},
	cache: false,
	contentType: false,
	processData: false
	xhr: function() {  // Custom XMLHttpRequest
		            
		var myXhr = $.ajaxSettings.xhr();
		            
		if (myXhr.upload) { // Avalia se tem suporte a propriedade upload
		myXhr.upload.addEventListener('progress', function (evt) {
		     if (evt.lengthComputable) {
					            
				var percentComplete = evt.loaded / evt.total;

				var porcentagem = percentComplete * 100;

				console.log(parseInt(porcentagem)+'%');

				$('#docs-objeto3 #loader-bar .loadbar-label').text(parseInt(porcentagem)+'%');
				$('#docs-objeto3 #loader-bar .progress-bar').width(parseInt(porcentagem)+'%');

				if(porcentagem == 100){
					            	
					// window.location.reload(true);
					location.reload(true);
					// document.location.href = 'detalhe-objeto.php?objeto_id='+objeto_id+'&rt=success';
					// $(location).attr('href', 'detalhe-objeto.php?objeto_id='+objeto_id+'&rt=success')

				}

			}
		}, false);
	}
	return myXhr;

	},
	close: function(){

		$("#docs-objeto3 #forms").show();
		$("#docs-objeto3 #loader-bar").hide();

	}
});

}

Note that I am using the location.reload(true); method that works perfectly in Firefox, locally works in Chrome and firefox, but when I send to the server it does not work correctly in Chrome. I tested other ways as can be seen commented, always the same result.

When the page is reloaded the new content that has been inserted does not appreciate, having to give F5 again for the data to appear on the screen, I am not loading this content via ajax, it is loaded via normal php on the page. And because the content does not load the form that should disappear, it is still active allowing sending more documents, even if sending more than one document is blocked, this problem passes to the user that the doc was not sent. Since the information does not appear on the screen.

    
asked by anonymous 11.09.2017 / 16:11

2 answers

0

For some reason I do not know (if anyone knows), the headers of the called file were not being processed before the redirect, I found this sent a larger file and redirected normal. So I added the following line that still needs to be optimized.

setTimeout(function(){	            		
  location.reload(true);
}, 3000); //Tempo 3 segundos antes de redirecionar.
    
11.09.2017 / 17:58
0

Is it the best solution? DO NOT. But you can try to use it for testing:

window.location.href = window.location.href;

In my opinion, it's a bit nutty, but for browser testing it works.

    
11.09.2017 / 20:25