Home  >  Article  >  Backend Development  >  网页不添加ruquire则正常

网页不添加ruquire则正常

WBOY
WBOYOriginal
2016-06-23 13:41:191118browse

环境winserver2003 ie8
一共有3个页面
a页面向b页面发送数据
a页面js部分


<script></script>
<script> <br /> <br /> var myXmlHttpRequest=""; <br /> function getMessage(){ <br /> myXmlHttpRequest=getXmlHttpObject(); <br /> if(myXmlHttpRequest){ <br /> var url="GetMessageController.php"; <br /> var data="getter=<?php echo $loginuser; ?>&sender=<?php echo <br /> $username ?>"; <br /> myXmlHttpRequest.open("post",url,true); <br /> window.alert(data); <br /> myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); <br /> myXmlHttpRequest.onreadystatechange=function chuli(){ <br /> <br /> if(myXmlHttpRequest.readyState==4){ <br /> if(myXmlHttpRequest.status==200){ <br /> window.alert("dsfsd"); <br /> var cities=myXmlHttpRequest.responseXML.getElementsByTagName('city'); <br /> var city_name=cities[1].childNodes[0].nodeValue; <br /> window.alert(city_name); <br /> }}} <br /> //发送请求 <br /> myXmlHttpRequest.send(data); <br /> }else{ <br /> window.alert("失败"); <br /> }} <br /> window.setInterval(" getMessage()",5000); <br /> </script>


回复讨论(解决方案)

b页面引用c页面

require_once 'MessageService.class.php';//去掉这句就不会提示缺少对象。文件存在名字也没错
header("Content-Type:text/xml;charset=utf-8");
header("Cache-Control:no-cache");
$getter=$_POST['getter'];
$sender=$_POST['sender'];
$mesList="杭州温州宁波

";
echo $mesList;
?>

c页面
class MessageService{
}
?>

你不要 a页面、b页面、c页面的

既然 var url="GetMessageController.php";
那么 GetMessageController.php 是哪个?

 GetMessageController.php是b页面
'MessageService.class.php';是c页面

错误信息是什么?

MessageService.class.php
这里有什么?

MessageService.class.php
这里有什么?


就是那个c页面只有个空类

错误信息是什么?


缺少对象还是啥对象来着。
提示在myXmlHttpRequest这个对象上,我只要去掉引用哪句,其地方不改就可以了。就是搞不明白为什么,郁闷死了。
我已经重新用json重新写了。

重新用json写了该功能,现在慢慢等解答。下面补上剩下代码。

a页面 chatroom.php的代码
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


$username=$_GET['username'];
//去除utf-8空白
$username=trim($username);
session_start();
$loginuser=$_SESSION['loginuser'];
if(!$loginuser){
ob_start();
header("Location:login.php?errno=2");
ob_clean();
exit();
}
?>



<script></script>
<script> <br /> var myXmlHttpRequest=""; <br /> window.setInterval("getMessage()",5000); <br /> <br /> function getMessage(){ <br /> <br /> myXmlHttpRequest=getXmlHttpObject(); <br /> if(myXmlHttpRequest){ <br /> var url="GetMessageController.php"; <br /> var data="getter=<?php echo $loginuser; ?>&sender=<?php echo $username ?>"; <br /> myXmlHttpRequest.open("post",url,true); <br /> window.alert(data); <br /> myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); <br /> <br /> myXmlHttpRequest.onreadystatechange=function chuli(){ <br /> if(myXmlHttpRequest.readyState==4){ <br /> if(myXmlHttpRequest.status==200){ <br /> window.alert("dsfsd"); <br /> var cities=myXmlHttpRequest.responseXML.getElementsByTagName('city'); <br /> var city_name=cities[0].childNodes[0].nodeValue; <br /> window.alert(city_name); <br /> } <br /> } <br /> } <br /> //发送请求 <br /> myXmlHttpRequest.send(data); <br /> }else{ <br /> window.alert("失败"); <br /> } <br /> } <br /> </script>

聊天窗口





正在和聊天











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