Extension Server communication
How can an extension communicate with a server?
how do they exchange data?
suppose u sign in to a page, how does the connection between th
extension and server be after sign in?
how does the server send a message to one of these signed in clients?
i tried the communication part in ajax httprequest response
objects...the javascript n php are communicating...but wen i
integrated the code into the extension, it din give output.
i heard that ajax wont work well in the backend in xul
applications..something about xml render....is there any other way for
carrying out this extension server communication...
a Mozilla Firefox extension which connects two or more people located
at geographically distant areas, who happen to be browsing the same
website simultaneously. It shows you other people who visit the same
websites as you are.
The extension informs the server whenever the user clicks the
EnableChat button to start a chat session.
The server retrieves from its database, the list of users who are
currently online in that site and returns it.
The user can then click on any username for opening a chat session.
this is my xul file:
<?xml version="1.0"?>
<overlay id="blaze-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script language="javascript" type="text/javascript" src="chrome://
blaze/content/connect.js" />
<toolbox id="navigator-toolbox">
<toolbar id="blaze-toolbar" align="center" toolbarname="blaze"
accesskey="B" class="chromeclass-toolbar" context="toolbar-context-
menu" hidden="false" persist="hidden">
<label control="some-text" value="Username"/>
<textbox id="some-text"/>
<label control="some-password" value="Password" />
<textbox id="Userpassword" type="password" maxlength="15"
onkeypress="if(event.keyCode == 13)
{alert('good');verifyusernamepasswd();}"/>
<toolbarbutton id="blaze-button" tooltiptext="Click for chat with
other users"
label="Enable Chat" oncommand="getUsers('php.com');" />
<toolbarbutton id="blaze-logout" tooltiptext="Click to log out of
BLAZE" label="Logout" oncommand="alert('bye!')" />
</toolbar>
</toolbox>
<statusbar id="status-bar">
<statusbarpanel id="my-panel" label="Hello, World" />
</statusbar>
</overlay>
getUsers.js
var xmlhttp;
function getUsers(u)
{
alert('hi');
xmlhttp=new XMLHttpRequest();
var url="servercode.php?q="+u;
xmlhttp.onreadystatechange= useHttpResponse;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function useHttpResponse()
{
alert(xmlhttp.readyState);
if (xmlhttp.readyState==4 )
{
alert(xmlhttp.responseText);
}
}
verifyusernamepasswd():
var xml;
function verifyusernamepasswd()
{
var usernamebox=document.getElementById("some-text");
var passwordbox = document.getElementById("Userpassword");
var username=usernamebox.value;
var password=passwordbox.value;
alert(username);
xml=new XMLHttpRequest();
var url="loginvalidate.php";
var param="q="+username+"&p="+password;
xml.open("POST",url,true);
xml.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
xml.setRequestHeader("Content-length", param.length);
xml.setRequestHeader("Connection", "close");
xml.onreadystatechange=statechanged1();
xml.send(param);
}
function statechanged1()
{
if(xml.readyState==4 && xml.status==200)
alert(xml.responseText);
}
servercode.php
<?php
$q=$_GET["q"];
$con=mysql_connect("localhost","root","blaze");
if(!$con)
{die('could not connect to database'.mysql.error());
}
mysql_select_db("BLAZE",$con) or die("No such Db");
$result=mysql_query("SELECT * FROM USERURL WHERE url='php.com'");
if($result == null)
echo 'halla';
header('Content-type: text/html');
echo '{Users:[';
while($row=mysql_fetch_array($result))
{
echo"{UserId:".$row[UsrID]."},";
}
echo "]}";
mysql_close($con);
?>
loginvalidate.php:
<?php
$con = mysql_connect("localhost","root","blaze");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$username=$_POST['username'];
$password=$_POST['password'];
var $false="false";
var $true="true";
mysql_select_db("BLAZE",$con);
$result=mysql_query("SELECT Userid,Password FROM USERTABLE WHERE
Userid='$username'");
if($result==NULL)
echo $false;
else
{
$row=mysql_fetch_array($result)
if((strcmp($row["Userid"],$username)!=0)||(strcmp($row["Password"],
$password)!=0))
{
echo $false;
}
else
echo $true;
}
?>
my problem is that i cant get the response of the php to the
extension. there is proper connection between my javascript n
php...for eg, i ran the javascript in html in /var/wwww here server
code is n i got output. but wen i integrated it with the extension, i
din get the response from php to the extension...
what could possibly be wrong????????
Last edited by Neethusha; 03-18-2010 at 11:49 AM.
|