-3

I want to call php function while call that function I need to pass parameter, when click on some text, It has to call the method called test(); How to do this.

I don't know anything about ajax.I have taken this code to try it.To try I have used simple code it is also not working.

This is Ajax.html file

<!DOCTYPE html>
<html>
<head>
<body>
  <p>Click Me</p>

<script>
    $(document).ready(function() {
    $("p").click(function(){
    $.ajax({
    url:"script.php", //the page containing php script
    type: "POST", //request type
    success:function(result){
    alert(result);
    }
  });
});
})
</script>
</body>
</head>
</html>

script.php contains,

<?php 
function test(){
  echo "Hello";
  }
 ?>

how to call php function when user click on some text.where I have to call that test() method. Can Any one help me?

Vidya
  • 153
  • 1
  • 2
  • 14

1 Answers1

0

Either you need to call when page called

 <?php 
  test()//mind it
  function test(){
    echo "Hello";
  }
 ?>

Or use any param like name of action

 <?php 
  if(isset($_GET['action']) && $_GET['action']==1){
      test()//mind it
  }else{
      otherFunc()//mind it
  }
  function test(){
    echo "Hello";
  }
 ?>

Set action in url

url:"script.php?action=1",
freelancer
  • 1,174
  • 5
  • 12