Ajax响应包含的内容超出预期

时间:2011-12-12 09:19:28

标签: ajax request response

Filestructure

JS / scripts.js中

库/ libary.php

模块/ page.php文件

模量/ 404.php

的index.php

文件说明

index.php查看url的路径部分是什么,并且需要该文件。所以www.test.com/page将需要modules / page.php。一些代码:

$file = (DIR . 'modules/'.$action.'.php');
if(!file_exists($file))
{
    $file = DIR . 'modules/404.php';
}

//Get file
require($file);

page.php的正文如下所示:

<input type='submit' value='getTime' onClick='getTime()' />

JS函数如下所示:

function updateStatus()
   {

if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
} else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    document.getElementById("content").innerHTML=xmlhttp.responseText;
    }
}
xmlhttp.open("POST","library/library.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("status=page");
    }

库文件包含以下内容:

return time();

问题

问题是reponseText不包含时间,它还包含404.php页面。这是因为我的index.php。他寻找一个modules / library.php,它不存在(不在模块目录中)。

所以我的问题是,ajax请求和响应的方式是什么?如何在不将library.php放入模块目录的情况下解决这个问题?

我真正的问题有点复杂,但它的根源与我在这里描述的问题相同。因此,抽出时间不是我的问题,只能说明我的问题。

0 个答案:

没有答案
相关问题