更新时间:2023-02-07 13:49:40
技术上不可行。但是,您可以对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.