0
I wonder if it is possible to update the contents of a load. Example:
I have a form on the page "html submit."
<form action="submeter" method="post">
<input type="text" name="nome" value="" />
<input type="submit" value="Enviar" />
</form>
I load this form in another page...
<div id="conteudoFixo">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vel neque eu magna vestibulum tincidunt. Duis a lobortis felis, id pulvinar nulla. Pellentesque fermentum sollicitudin nisl, at molestie felis pretium vel. Donec tellus mauris, imperdiet sed sagittis in, consectetur quis ex.
</div>
<div id="conteudoMuda">
<button id="botaoForm">Mostrar Form</button>
</div>
And I use the jquery to load:
jQuery('#botaoForm').click(function(){
jQuery('#conteudoMuda').load('/enviar_formulário.html');
});
The problem is, when I give Submit the form, it redirects me (action="submit"). I would like to send the data without being redirected.
Note: I cannot use ajax to submit the form.
Ajax code:
/* submeter form trocar nick */
jQuery('form[name="post"]').submit( function(){
event.preventDefault();
jQuery.ajax({
dataType:'html',
type : 'POST',
data : ({username_edit: jQuery("#username_edit").val(), user_rank : jQuery("#rankusren").val(), signature : jQuery("#assinaturaa").val(), profile_field_10_5 : jQuery("#profile_field_10_5").val(), user_status : jQuery("#user_status_yes").val(), user_allowpm : jQuery("#user_allowpm_yes").val(), user_allowavatar : jQuery("#user_allowavatar_yes").val(), mode : jQuery("[name='mode']").val(), agreed : jQuery("[name='agreed']").val(), id : jQuery("#idusrpnl").val()}),
success : function( resultado ){
alert('Nome trocado!');
}
});
});
/* fim do form trocar nick */
Video showing that the form is not submestic with ajax. But with ajax, it is normally submitted
https://www.youtube.com/watch?v=JESNg-w2HUw&feature=youtu.be
Give me a valid reason not to use ajax.
– BrTkCa
I am working on a forum platform, and ajax with POST does not work, just GET
– Victor Eyer
I even tried to do it, but it submits the forum without sending the values, and returns the Success. Even using error or fail(), I keep getting Success
– Victor Eyer
You can do it with GET and send the data as query string as well.
– BrTkCa
Could you give an example? I will add the code I tried in the question
– Victor Eyer
Do you want to make an asynchronous POST request without being asynchronous? I don’t get it.
– Woss
Actually, I asked the question because I couldn’t do it with ajax. So I thought of ways to do the system without. I thought about using iframe, but I don’t think it’s a good solution.
– Victor Eyer
Why does it say that this POST is not asynchronous @Andersoncarloswoss?
– BrTkCa
@Lucascostat the standard form submission is a synchronous request, as the browser is redirected to the page and should wait for the server response.
– Woss
The Submit is synchronous, the post with Ajax is asynchronous @Andersoncarloswoss, which was his example. You can use this way to serialize the form for example.
– BrTkCa
That’s what I’m saying: he said he can’t use AJAX but wants the request to be asynchronous.
– Woss