0
Good morning.
My Ajax function returns a string and prints it via innerHTML within a div. This string is:
<div>
<p>Login bem sucedido.</p>
<p>Redirecionamento em ação.</p>
</div>
<script> location.reload(); </script>
I have done this in other projects, but the function does not perform page re-load. I also tried an Alert, but it did not work at all.
What am I doing wrong?
Follows ajax Success function:
function success(value) {
if (value.length > 0) {
// msg = elmento div#msg
msg.innerHTML = value;
} else {
msg.innerHTML = ('<div id="error"><div class="inform"><p>Nenhum valor retornado.</p></div></div>');
}
}
Dude, if you do a Load the user won’t even see the message right (or they won’t even see, since the page would be reloaded immediately). That’s what you want?
– Sam
Have you tried the classic
setTimeout(function() {
 document.location.reload(true);
}, 5000);
– Fabiano Monteiro
Good afternoon, @Sam. The intention is to put a setTimeout, but no function works: be it Reload alone, setTimeout, or Alert.
– E. Coelho
Good afternoon, @Fabianomonteiro. I tried everything. No function works.
– E. Coelho
have tried to load into the div? or call jquery html(str)
– Jasar Orion
http://api.jquery.com/load/
– Jasar Orion
@E.Coelho Do you only want a Reload? And what is the purpose of Reload? Your code with the
setTimeout
, here on my PC works. It keeps giving Re-load. I think it’s best to explain what your goal is with this, and what is currently on your system. You have to callappendChild
to attach the DOM element to an existing element.– Fabiano Monteiro
I think the most important thing is to check if there are any error messages in the browser console. From this it is easier to discover the problem, because with the current information any help is kick.
– fernandosavio
Good afternoon, @Jasarorion. I am not using libraries in this project. About using the . load() function, I have never used it in my projects. I’ve always used . html() in jQuery.
– E. Coelho
Good afternoon, @Fabianomonteiro. I want the functions to work. I’m using pure javascript in this project. I’ll try the appendchild and I’ll give you feedback.
– E. Coelho
Good afternoon, @fernandosavio. No error message on the console. I will try the appendchild, as Fabiano said and I already give a feedback.
– E. Coelho
With jQuery the code works, but with pure JS not because the return comes as string. Now why in jQuery works is that I do not know.
– Sam
Put the Ajax code too, the problem may be there.
– fernandosavio
@E.Rabbit I will pass a code, until I understand what you want:
<div id="meuidentificador"></div><script>document.getElementById("meuidentificador").innerHTML += "<p>Login bem sucedido.</p><p>Redirecionamento em ação.</p>" + setTimeout(function() { document.location.reload(true); }, 5000);</script>
I just didn’t understand the following is re-load or redirect?– Fabiano Monteiro
@fernandosavio, I edited the question, putting the function Success(). I tried appendchild, but it didn’t work: it treats HTML code as text and printa <div>Message... (etc).
– E. Coelho
@Fabianomonteiro, the page is dynamic at the base: if the session is started, it will include another page, otherwise it will continue in the login form. There is "printing" redirect to the user. When performing Reload(), PHP checks that the session was started in includes the options panel for the user.
– E. Coelho
Still hard to know where the error comes from with little information. I did that snippet who makes an ajax request and uses
innerHTML
and everything works very well.– fernandosavio