Here what I exactly need is, if I move over the HTML button, specific div tag should be reloaded without reloading whole page.
            Asked
            
        
        
            Active
            
        
            Viewed 1.2k times
        
    -1
            
            
        - 
                    3You need to use AJAX to accomplish that. There are plenty of tutorials on google. – ksbg Jun 11 '15 at 11:01
- 
                    https://www.google.com/search?q=ajax – Aaron W. Jun 11 '15 at 11:01
- 
                    The only way to execute PHP from JS is AJAX. You can use AJAX call to load PHP function on mouse hovering. – Ravi Patel Jun 11 '15 at 11:08
2 Answers
1
            
            
        PHP works on the server side, and JavaScript on the client side. So to do this, you would have to make a request to the server. If you want to use plain JavaScript, take a look at Ajax:
http://www.w3schools.com/ajax/
<script>
function myPhpFunctionCall()
{
  var xmlhttp;
  xmlhttp=new XMLHttpRequest();
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      // Do something with the results here
    }
  }
  xmlhttp.open("GET","my_function.php",true);
  xmlhttp.send();
}
</script>
Or, if you want to use jQuery, you can use their get method:
<script>
    $.get('http://yourdomain/your_script.php');
</script>
 
    
    
        Jorick Spitzen
        
- 1,559
- 1
- 13
- 25
- 
                    1If you could provide some code supporting your answer, it would form a better answer. Just links in the answer, may make it non useful, if the links get modified in the future. – Prerak Sola Jun 11 '15 at 11:03
- 
                    1I would love to add a code example, but since the question does not really give a specific task to solve, I really can't add a more useful than the code example on page 1 of that w3schools tutorial... – Jorick Spitzen Jun 11 '15 at 11:08
-3
            
            
        Simple way to solve this any of your function in place of json_encode() :
$(document).ready(function() {
         var php_var = '<?php echo json_encode($form); ?>';          
});
$('#element').hover(function() {
         $('#form_container').html(php_var);
}, function() {
         $('#form_container').html('');
});
 
    
    
        viralchampanery
        
- 397
- 1
- 7
- 16
 
    