Javascript 如何从PHP文件中获取值并将其插入index.PHP

Javascript 如何从PHP文件中获取值并将其插入index.PHP,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,如何从PHP文件中获取值并将其插入index.PHP 这是我的档案: image.php index.php 如果上述所有代码都在同一个fileindex.php中,我可以得到该值 但是我想从image.php到index.php获得$newimgurl只需通过IMG标记的SRC属性调用php文件: <img src="image.php" /> 编辑: 能否将image.php包含在index.php中 <?php include_once("image.php")

如何从PHP文件中获取值并将其插入index.PHP

这是我的档案:

image.php

index.php

如果上述所有代码都在同一个fileindex.php中,我可以得到该值


但是我想从image.php到index.php获得$newimgurl

只需通过IMG标记的SRC属性调用php文件:

<img src="image.php" />
编辑:

能否将image.php包含在index.php中

<?php
    include_once("image.php")
?>

在index.php中编写

<?php
   include_once "image.php";
   echo $newimgurl;
包含image.php后,您将可以访问image.php文件中分配的变量

你可以阅读更多关于它的内容


您还可以更改此行echo$newimgurl;退还$newimgurl;在index.php中包含image.php

$newimgurl=file\u get\u contentsimage.php;我使用了这段代码,但没有得到newimgurl值它得到了所有image.php文件代码而不仅仅是$newimgurl关于在index.php中包含image.php的内容是什么?我编辑了答案,我想通过AJAX POST获得值,比如$.AJAX{type:POST,url:'image.php',data:{},success:functiondata{}
$url = file_get_contents("image.php");
<?php
    include_once("image.php")
?>
<?php
   include_once "image.php";
   echo $newimgurl;