Skip to content Skip to sidebar Skip to footer

Displaying Php Results Inside A Div

Let me explain in detail what I want to achieve. I have 3 pages: index.html, form.html and result.php. Using jquery when I click a button in index.html it will load form.html insid

Solution 1:

Instead of submitting the form the normal way, consider calling result.php with Ajax (jQuery.post() for example). Then you can use the success-callback to inject the returned value.


Solution 2:

you can do this by jquery and ajax below is the simple way

Contents of result.php:

<?php
   $received=$_POST['pass'];
   echo 'Received: '.$received;
?>

make a ajax request like ,make a form id like id="from_one"

$("#from_one").submit(function(){
$.ajax({
  url: 'result.php',
  type: "POST",
  data:{pass:$('input[type=pass]')}
  success: function(data) {
     //here append the result to the div you want 
     // in data you will get the result 
  }
});
});

Solution 3:

$('#changepass').click(function(){
var id = $('input#pass').val();
$.post( 'http://domain.com/result.php' { id : id },
        function(response){
            $('div#div_for_form').html(response);
        });

}); 

Solution 4:

Include your results.php in the div to have it on the right place.


Solution 5:

Try below one :

in form.html change form tag :

<form method="POST" action="" onsubmit="return callphp()">

in index.html add function callphp() :

function callphp()
{
  var xmlhttp;
     if (window.XMLHttpRequest)
        {
       xmlhttp=new XMLHttpRequest();
        }
     else
        {
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
     xmlhttp.onreadystatechange=function()
        {
       if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
         document.getElementById("div_for_form").innerHTML=xmlhttp.responseText;

      }
      }  
       xmlhttp.open("POST","result.php",true);
       xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
       xmlhttp.send();
}

Post a Comment for "Displaying Php Results Inside A Div"