John Davidson

I need the url in the ajax script to be a variable from a php file but I don't know how to do this


The top section has the variables and forms. The program calls an html page depending on who logs in. I need to be able to pull the page based on login information.

I pull the page number from the url when the page is called. I need to use that page number in the ajax part of the program at the bottom to pull the data off the right page and put it in the chatbox.

Right now I can't pull the right page. I am having a problem setting a variable in the ajax url:

I tried using "" but it will load the chatbox inside the chatbox as an image.

if($_POST['name'] != ""){
$_SESSION['name'] =
echo '<span class="error">Please type in a name</span>';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="">
<title>Chat - Customer Module</title>
<link type="text/css" rel="stylesheet" href="style1.css" />

<div id="wrapper">
<div id="menu">
<p class="welcome">Welcome, <b><?php echo $_SESSION['name']; ?>
<p class="logout"><a id="exit" href="#">Exit Chat</a></p>
<div style="clear:both"></div>
<div id="chatbox"><?php
if(file_exists($log) && filesize($log) > 0){
$handle = fopen($log, "r");
$contents = fread($handle, filesize($log));
echo $contents;
$contents = 'Welcome!';
file_put_contents($log, $contents);
echo $contents;

<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="63" />
<input name="submitmsg" type="submit" id="submitmsg"
value="Send" />
<br />
<form action="upload.php" method="post" enctype="multipart/form-
Select image to upload:
<input type="file" name="fileToUpload" />
<input type="submit" value="Upload Image" name="submit" />
<script type="text/javascript"
<script type="text/javascript">
// jQuery Document
//If user submits the form
var clientmsg = $("#usermsg").val();
$.post("post.php", {text: clientmsg});
$("#usermsg").attr("value", "");
return false;

//Load the file containing the chat log
function loadLog(){
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;

url: "chat/9999.html",

cache: false,
success: function(html){
$("#chatbox").html(html); //Insert chat log into the #chatbox div
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal');
//Autoscroll to bottom of div
setInterval (loadLog, 2500); //Reload file every 2.5 seconds

//If user wants to end session
var exit = confirm("Are you sure you want to end the
if(exit==true){window.location = 'index.php?logout=true';}

I have updated to give you more code. I tried using the "" but the form isn't acting right. It keeps loading the form inside the form again.

I need the "chat/9999.html" to be a variable so it can bring up one of a few pages.

My Answer:
't know how to do it. Can you help me with this?

Rate this post

3 of 5 based on 2441 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us