How can we name Php functions based on the Java condition of the If-else script?

How can we call Php functions with an If-else JavaScript condition.

For instance,

 if (top == self) {

  // not in any kind of frame

} else {

// in a frame

// calling php function

}
</script>

Here, the PHP () exit function is called for the if and else conditions. I need to call this function only for a part.

Please advise me.

Thank. Prabhu

+3
source share
2 answers

Technically impossible. However, you can make an AJAX call to the PHP page and get the values ​​returned by it.

PHP (test.php):

<?php
$x = 10;
$y = 20;
$val = $y / $x;

echo $val;
?>

Javascript ( jQuery ):

$(document).ready(function() {
   $.ajax({url: 'test.php',
      type: 'POST',
      success: function(data){
         //takes the value returned by test.php and
         //puts it directly into the element with 
         //id = someElement
         $('#someElement').html(data);
      }
});

As for calling exit();and creating a page on which JavaScript stop processing is performed, you simply cannot, unless you control the logic on the same page in PHP and call exit();from there.

+5

javascript php.

, (php) , exit();

javascript , : return; false;

0

All Articles