I've this simply code in status.php:
<script type="text/javascript">
$(document).ready(function() {
$("form#iscrizione").submit(function(){
var ordine = $("#ordine").val();
var cognome = $("#cognome").val();
$.ajax({
type: "POST",
url: "http://****/new/action.php",
data: "cognome=" + cognome + "&ordine=" + ordine,
dataType: "html",
success: function(risposta) {
$("div#risposta").html(risposta);
alert("ok!");
},
error: function(){
alert("Chiamata fallita!!!");
}
});
return false;
});
});
</script>
In my page (status.php) it works!
But when I put a frame of status.php in index.php it doesn't work and change only the url like: ?cognome=Esposito&ordine=2121237391
What should I to in order to work as a frame in index.php ?
I used
type: "GET",
url: "http://stackoverflow.com/questions/32554239/ajax-post-without-refresh",
instead of your
type: "POST",
url: "http://****/new/action.php",
AND it works fine. (Just click on "Run snippet", it shows an error because the url doesn't support cross-domain)
$(document).ready(function() {
$("form#iscrizione").submit(function(){
var ordine = $("#ordine").val();
var cognome = $("#cognome").val();
$.ajax({
type: "GET",
url: "http://stackoverflow.com/questions/32554239/ajax-post-without-refresh",
data: "cognome=" + cognome + "&ordine=" + ordine,
dataType: "html",
success: function(risposta) {
$("div#risposta").html(risposta);
alert("ok!");
},
error: function(){
alert("Chiamata fallita!!!");
}
});
return false;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="iscrizione">
<input type="text" value="get" id="cognome"><input type="text" value="get" id="ordine"><input type="submit" value="get"></form><div id="risposta"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With