-1

Here what I exactly need is, if I move over the HTML button, specific div tag should be reloaded without reloading whole page.

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Beena Gates
  • 85
  • 1
  • 2
  • 11

2 Answers2

2

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,441
  • 1
  • 14
  • 23
  • 1
    If 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
  • 1
    I 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
  • 377
  • 1
  • 6
  • 16