Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax post without refresh

Tags:

jquery

ajax

php

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 ?

like image 843
Genny Avatar asked Feb 02 '26 03:02

Genny


1 Answers

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>
like image 167
Elias Nicolas Avatar answered Feb 04 '26 18:02

Elias Nicolas