search
HomeBackend DevelopmentPHP Tutorial为何取不出正确的的文件内容

我有三个文件,分别是1.php、2.php和Ajax.js
1.php内容如下


$i=   //对变量i进行一系列运算

include("2.php")



2.php内容如下
echo $i;

Ajax.js大体内容如下:


每隔1秒中请求一下2.php的返回内容;
httpxml.open("get","2.php");
XX.innerHTML=httpxml.responseText;


但是现在的问题是XX.innerHTML始终不变,不知为何?


已确认以下信息:
1、1.php中的$i内容时刻在变化
2、Ajax.js也按照规定频率执行请求动作


回复讨论(解决方案)

httpxml.open("get","2.php?t="+Math.random()); //请求地址加个随机数看看

httpxml.open("get"," 1.php");

2.php 只是输出 1.php 计算的结果

加随机数是没有问题的,能体现效果

2楼版主,请问问题在哪呢

不是说了吗?
那么你只访问2.php如何能得到1.php计算的结果呢?

提醒下,在1.php中,是在$i时刻变化的过程中执行include("2.php")的

呵呵,很感谢提醒。但是被提醒的应该是你
你 httpxml.open("get","2.php"); 访问的是 2.php !
而2.php中并没有数据计算

但是 2.php 里有获取变量$i啊?此变量来自1.php的计算

1.php和2.php里$i指的应该是同一变量吧,因为1.php里有include.不知我的理解可对

你确认直接调2.php能获得$i的值?

但是 2.php 里有获取变量$i啊?此变量来自1.php的计算
这么看还是拿出你的详细一些的代码,看一下吧~

不是页面缓存么?

老徐说的很清楚了吧 是1包含了2 你要请求1才能得到结果。。。。没理解include吧

我还是贴出来吧。最终想实现一个Ajax的例子,共4个文件,分别是form.php,1.php,2.php,Ajax.js
form.php内容如下:







<script></script>
1.php内容如下:
session_start();
for ($i;$i {
$_SESSION["temp"]=$i;
sleep(1);
}
?>
2.php内容如下:
session_start();
echo $_SESSION["temp"];
Ajax.js内容如下:

function createRequestObject() {
    var http;
    if (navigator.appName == "Microsoft Internet Explorer") {
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        http = new XMLHttpRequest();
    }
    return http;
}
function sendRequest() {
    var http = createRequestObject();
  
    http.onreadystatechange = function () { handleResponse(http); };
    http.send(null);
}
function handleResponse(http) {
    var response;
    if (http.readyState == 4) {
        response = http.responseText;
         http.open("GET", "2.php");
        document.getElementById("status").innerHTML = response;
       
        if (response              setTimeout("sendRequest()", 1000);
        }
        else {
           
            document.getElementById("status").innerHTML = "Done.";
        }
    }
}
function startUpload() {
    setTimeout("sendRequest()", 1000);
}

    document.getElementById("myForm").onsubmit = startUpload;


我想实现的效果是在form里点击“生成报表”按钮,则会每一秒钟显示一个从0到9的数字。

请高手帮助分析下原因,现在点击“生成报表”按钮后未有数字每隔1秒显示出来

有哪位高手指点下?

我知道你想做什么了(上传进度条)
那么对不起,你走进死胡同了

对于上传进度条,php提供了arc和upload两个扩展,并且php5.4也内置了类似功能
如何写?你搜索一下就知道了

你的应用不可能实现的原因在于默认的文件方式的 session
session 临时文件一旦被打开,就不能被其他进程再打开了
对于其他存储方式是否也是这样,没有测试过不好乱说

版主,我确实想实现类似进度条的功能,但是不是文件上传的进度条。(文件上传进度条的实现方式我已了解)
我想实现的是用Ajax获取1.php文件处理过程的进度(因为1.php是一个比较漫长的过程,可能需要几十秒钟,我想通过Ajax的方式将1.php的处理进度实时的展现给用户)

除了 seeeion,你就不能用其他共享手段传递数据吗?

我是菜鸟,请版主指教

难道没有人会么

哎。用数据库共享数据了

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.