我们如何根据Java脚本If-else条件调用Php函数? [英] How can we call Php functions based on the Java script If-else condition?
问题描述
如何在JavaScript If-else条件下调用Php函数。
How can we call Php functions with in the JavaScript If-else condition.
例如,
if (top == self) {
// not in any kind of frame
} else {
// in a frame
// calling php function
}
</script>
这里,PHP exit()函数调用if和else条件。我需要仅在其他部分调用该函数。
Here, PHP exit() function calling for both if and else conditions. I need to call that function for only in else part.
请告诉我。
谢谢。
Prabhu
Thanks. Prabhu
推荐答案
技术上不可行。但是,您可以对PHP页面进行AJAX调用并获取它返回的值。
Technically not possible. However you can make an AJAX call to a PHP page and get the values returned by it.
PHP(test.php):
PHP (test.php):
<?php
$x = 10;
$y = 20;
$val = $y / $x;
echo $val;
?>
Javascript( jQuery ):
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);
}
});
至于调用 exit();
并制作保存JavaScript停止处理的页面,除非你在PHP中控制同一页面上的逻辑并从那里调用 exit();
,否则你不能这样做。
As far as calling exit();
and making the page that holds the JavaScript stop processing, you just can't unless you control the logic on that same page in PHP and call exit();
from there.
这篇关于我们如何根据Java脚本If-else条件调用Php函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!