Trang Chủ | Diễn Đàn | Thành Viên (Đăng Ký) | Tìm Kiếm | Tutorial Room
PHP - Không nhận javascript trong PHP
Hỏi đáp, trao đổi về lập trình PHP.
- Các câu hỏi về tìm hosting hỗ trợ PHP xin hãy gởi vào box Web Hosting.
- Các câu hỏi về tìm chương trình forum, guestbook, hướng dẫn sử dụng, cấu hình các script viết bằng PHP...xin hãy gởi vào box Web Application.
First page Previous page  (Page 1 )   1   Next page Last page
Không nhận javascript trong PHP
Member
Member since
00:41 01-02-2010
Posts: 4
Fantasy Points: 15
Rank
sad Posted at 00:45 01-02-2010 Move Move Topic   Pin/Unpin Pin Topic   Lock Lock Topic
Chào các anh. Cho em hỏi chút ạ. E đang có file code PHP nhưng khi nhúng thêm đoạn code javascript vào thì nó không nhận được javascript. Em đang làm trên hệ thống LMS Moodle.
code:

<?php

require_once('../../config.php');

global $USER, $CFG,$userid;


$listofusers = "SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,
u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
FROM {$CFG->prefix}user u,
{$CFG->prefix}message m
WHERE m.useridto = '$USER->id'
AND u.id = m.useridfrom
GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt";

$users = get_records_sql($listofusers);

if (!empty($users)) {
$content->text .= '<ul class="list">';
$list_of_users = '| ';
foreach ($users as $user) {
$userid = $user->id;
$timeago = format_time(time() - $user->lastaccess);

// Cái này nó không nhận.....Sad
$content->text .= "<script language='javascript'>
document.write('This is my first JavaScript!');
</script>";

//------------->
$content->text .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$userid.'&amp;course=1" title="'.$timeago.'">';
$content->text .= print_user_picture($user, 1, $user->picture, 0, true, false, '', false);
$content->text .= fullname($user).'</a></div>';
$content->text .= '<div class="message"><a href="'.$CFG->wwwroot.'/message/discussion.php?id='.$userid.'" onclick="this.target=\'message_'.$userid.'\'; return openpopup(\'/message/discussion.php?id='.$userid.'\', \'message_'.$userid.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);"><img class="iconsmall" src="'.$CFG->pixpath.'/t/message.gif" alt="" />&nbsp;'.$user->count.'</a>';
$content->text .= '</div></li>';
$list_of_users .= fullname($user).' | ';



}
$content->text .='<!--'.get_string('new').' '.get_string('message','message').':'.$list_of_users.'-->';
$content->text .= '</ul>';
} else {
$content->text .= '<div class="info">';
$content->text .= get_string('nomessages', 'message');
$content->text .= '</div>';
}
echo $content->text;

?>


Mong các bro chỉ dùm....
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,504 time(s). 1 direct repli(es) and 4 indirect repli(es).
Title Poster
sad Không nhận javascript trong PHP
 
answer Re: Không nhận javascript trong PHP
NBThanh
Re: Không nhận javascript trong PHP
Forum Moderator
Member since
20:03 17-08-2001
Posts: 18,047
Fantasy Points: 154,606
Rank
answer Posted at 00:22 04-02-2010
Reply to Không nhận javascript trong PHP (silver1985)
"Nhận" làm sao được mà nhận!
Làm gì có cái kiểu:
$a .= "dòng 1
dòng 2
dòng 3";

Sửa lại:
$a .= "dòng 1"
. "dòng 2"
. "dòng 3";
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,480 time(s). 1 direct repli(es) and 3 indirect repli(es).
Title Poster
answer Re: Không nhận javascript trong PHP
 
answer Re: Không nhận javascript trong PHP
silver1985
Re: Không nhận javascript trong PHP
Member
Member since
00:41 01-02-2010
Posts: 4
Fantasy Points: 15
Rank
answer Posted at 21:43 04-02-2010
Reply to Re: Không nhận javascript trong PHP (NBThanh)
Cám ơn bro. để em thử xem có được không
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,464 time(s). 1 direct repli(es) and 2 indirect repli(es).
Title Poster
answer Re: Không nhận javascript trong PHP
 
answer Re: Không nhận javascript trong PHP
silver1985
Re: Không nhận javascript trong PHP
Member
Member since
00:41 01-02-2010
Posts: 4
Fantasy Points: 15
Rank
answer Posted at 22:06 04-02-2010
Reply to Re: Không nhận javascript trong PHP (silver1985)
Anh ơi nó không ảnh hưởng j cả. em đưa 2 file php đó lên để các bro chỉ giúp em

block_message.php

<?PHP //$Id: block_messages.php,v 1.13.4.6 2008/11/2 10:00:00 Amr Hourani

class block_messages extends block_base {
function init() {
global $CFG;
$this->userid = 0;
$this->title ='<img src="'.$CFG->wwwroot.'/theme/standard/images/image_index/43.gif" style="border: none; width:20px;height:20px;"/>';
$this->title .='<div style="margin-top:-20px; margin-left:26px;">'.get_string('messages','message').'</div>';
$this->version = 2007101510;
}

function has_config() {
return true;
}

function get_content() {
global $USER, $CFG, $COURSE, $userid;

if (!$CFG->messaging) {
return '';
}
if ($this->content !== NULL) {
return $this->content;
}

$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';

if (empty($this->instance) or empty($USER->id) or isguest() or empty($CFG->messaging)) {
return $this->content;
}

$this->content->text .='<div id="MessageInbox"></div>';
$session_key = sesskey();

if(empty($CFG->block_messages_refresh) || $CFG->block_messages_refresh == 0){ //never or not set!
$refreshtime = 86400000; //1 day?! no one will stay online for 24 hours!
}else{
$refreshtime = $CFG->block_messages_refresh;
}

$users = get_records_sql("SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,
u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
FROM {$CFG->prefix}user u,
{$CFG->prefix}message m
WHERE m.useridto = '$USER->id'
AND u.id = m.useridfrom
GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt");


//Now, we have in users, the list of users to show
//Because they are online
foreach ($users as & $user)
{
$user = $user->id;
}

$this->content->footer = '<a href="'.$CFG->wwwroot.'/message/index.php" onclick="this.target=\'message\'; return openpopup(\'/message/index.php\', \'message\', \'menubar=0,location=0,scrollbars,status,resizable,width=200,height=300\', 0);">'.get_string('messages', 'message').'</a>...';

$this->content->text .='
<script type="text/javascript">
<!--
function ShowMessage(){
var notfication = "'.get_string('check').' '.get_string('messages','message').'...";

document.getElementById("MessageInbox").innerHTML= notfication;
GetNewMessages();
}

function GetNewMessages(){
var objXMLHttp=null;
if (window.XMLHttpRequest){
objXMLHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject){
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp = objXMLHttp;
var url="'.$CFG->wwwroot.'/blocks/messages/check_messages.php";
url=url+"?updatemessage=1";
url=url+"&sid="+Math.random();
url=url+"&sesskey='.$session_key.'";
xmlHttp.onreadystatechange=stateChangedResult; // this is the function name to call
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}
function stateChangedResult(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("MessageInbox").innerHTML= xmlHttp.responseText;
var titlebox = xmlHttp.responseText;
if(titlebox.search( /<!--/ ) != -1){
titlebox = titlebox.slice( titlebox.search( /<!--/ ) );
titlebox = titlebox.replace(/<!--/,"","");
titlebox = titlebox.replace(/--><\/ul>/,"","");




}else{
document.title="'.$COURSE->shortname.'";
}
}
}
setInterval(ShowMessage, '.$refreshtime.'); // Reload every 60 seconds :-)
GetNewMessages(); // to load with page load!
//-->
</script>';
return $this->content;
}

}

?>


check_message.php

<?php //Code by Amr Hourani a.hourani@gmail.com

require_once('../../config.php');
//require_login();
global $USER, $CFG,$userid;

//if(!confirm_sesskey()) error("session mismatch!");

$listofusers = "SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,
u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
FROM {$CFG->prefix}user u,
{$CFG->prefix}message m
WHERE m.useridto = '$USER->id'
AND u.id = m.useridfrom
GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt";

$users = get_records_sql($listofusers);

$content ='';

foreach ($users as $user) {
$userid = $user->id;
}
if ($user->id = null)
{
$content .= '<li class="listentry"><div class="user"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course=1" title="'.$timeago.'">';
$content .= print_user_picture($user, 1, $user->picture, 0, true, false, '', false);
$content .= fullname($user).'</a></div>';
$content .= '<div class="message"><a href="'.$CFG->wwwroot.'/message/discussion.php?id='.$user->id.'" onclick="this.target=\'message_'.$user->id.'\'; return openpopup(\'/message/discussion.php?id='.$user->id.'\', \'message_'.$user->id.'\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);"><img class="iconsmall" src="'.$CFG->pixpath.'/t/message.gif" alt="" />&nbsp;'.$user->count.'</a>';
$content .= '</div></li>';
echo'<script type="text/javascript"> alert ("ok"); </script>';
}
else
{
$content .= '<div class="info">';
$content .= get_string('nomessages', 'message');
$content .= '</div>';
echo '<script type="text/javascript"> alert("hey")</script>';

}






print_r($content);

?>


nếu chạy trực tiếp file javascript thì nó vẫn nhận còn quét qua file block_message thì chả có tăm hơi j
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,462 time(s). 1 direct repli(es) and 1 indirect repli(es).
Title Poster
answer Re: Không nhận javascript trong PHP
 
answer Re: Không nhận javascript trong PHP
NBThanh
Re: Không nhận javascript trong PHP
Forum Moderator
Member since
20:03 17-08-2001
Posts: 18,047
Fantasy Points: 154,606
Rank
answer Posted at 22:12 04-02-2010
Reply to Re: Không nhận javascript trong PHP (silver1985)
Thử view source của trang web xem mã HTML nó sinh ra thế nào, có đúng không?
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,460 time(s). 1 direct repli(es) and 0 indirect repli(es).
Title Poster
answer Re: Không nhận javascript trong PHP
 
answer Re: Không nhận javascript trong PHP
silver1985
Re: Không nhận javascript trong PHP
Member
Member since
00:41 01-02-2010
Posts: 4
Fantasy Points: 15
Rank
answer Posted at 00:53 05-02-2010
Reply to Re: Không nhận javascript trong PHP (NBThanh)
Em chạy riêng file check_message thì nó vẫn nhận javascript còn khi reload lại trang check_message thông qua code ajax ở file block_message thì nó không đựoc
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,451 time(s). 0 direct repli(es) and 0 indirect repli(es).
First page Previous page  (Page 1 )   1   Next page Last page

Permissions: Create Topic: No  |  Reply Topic: No  |  Attach File: No  |  Make Poll: No

Vietnamese Keyboard: AUTO TELEX VNI VIQR VIQR* OFF

Go top || Print page ||

All logos, trademarks and graphics artwork in this site are property of their respective owners.
Opinions expressed in articles within this site are those of their owners and may not reflect the opinion of TXBB.

TXBB: Home - Disclaimer - Help - Contact
Copyright (C) 2000-2006 TXBB. All rights reserved.

TreXanh Bulletin Board v2.0 (Build: #332 Nov 21, 2006)

DEBUG INFORMATION
Execution 0.185s - SQL used 6s - Concurrent process(es) 0