Jump to content


PHP In Javascript


1 reply to this topic

#1 Tomy

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 15 July 2007 - 09:24 AM

Hey there im using an ajax refresher and i was wanting to no how can i put php into the javascript heres the normal code
<script type="text/javascript">
var xmlHttp

function GetXmlHttpObject(){
var objXMLHttp = null;

if(window.XMLHttpRequest){
try{
objXMLHttp = new XMLHttpRequest();
}catch (e){
objXMLHttp = false;
}
}else if(window.createRequest){
try{
objXMLHttp = new window.createRequest();
}catch (e){
objXMLHttp = false;
}
}else if(window.ActiveXObject){
try{
objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
objXMLHttp = false;
}
}
}


return objXMLHttp;
}
function GetShouts()
{
xmlHttp = GetXmlHttpObject()
if (xmlHttp == null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="messagesL.php"
xmlHttp.open("GET", url, true) // Open the shout.php url and get the latest shouts
xmlHttp.onreadystatechange = function () // When the http status changes
{
if (xmlHttp.readyState == 4) // If it's a green light...
{
if (xmlHttp.status == 200) // If it's fully loaded...
{
document.getElementById("chatarea").innerHTML = xmlHttp.responseText; //Update the div with the current shouts!
}
}
};

xmlHttp.send(null);
}
GetShouts();
setInterval("GetShouts()", 1000); // Get shouts every second



function saveData()
{
xmlHttp = GetXmlHttpObject()
if (xmlHttp == null)
{
alert ("Browser does not support HTTP Request")
return
}
if(document.shout.message.value == "") // If the message is blank,...
{
alert("Please go back and enter a message.") // Alert them!
return // Return and don't submit
}
if(document.shout.username.value == "") // If the username is blank.,.,.,.,.!1,1.,
{
alert("Please go back and enter a username.") // Alert them!
return // Return and don't submit
}

xmlHttp.open('POST', 'input.php'); // Open shout.php with the act of send so we can submit data.
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // Set it as a form being sent
xmlHttp.send('&username=' + document.shout.username.value + '&shout=' + document.shout.message.value); // Send the data!
document.shout.message.value = ''; // Update the message box to nothing
document.shout.message.focus(); // Focus the message box so they don't have to do alot of clicking
}

function blockSubmit() {
	sendChatText();
	return false;
}
</script>

and where it says var url="messagesL.php" i want it so itll get the id such as messagesL.php?room=$room
<?
$room = $_GET['room'];
?>
but i dont no how to put them together can some one help me please?

#2 Braunson

    Young Padawan

  • Members
  • Pip
  • 237 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 15 July 2007 - 11:38 AM

REPLACE
messagesL.php
WITH
messagesL.php?room=<?=$_GET["room"];?>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users