473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

retrieving data via php/sql, displaying via AJAX & Thickbox...issues!

Hiya,

I'm trying to get a AJAX driven update to my list of news articles, so
when users click the title of the news article, it pops up the article
content in a thickbox overlay. Retrieving content from the database
via AJAX is no problem, that works and thickbox works too, I'm just
having problems getting them both running together! It seems like it's
too much information to cram into one poor little "a href=".... the
"onclick" called in the hyperlink needs to run 2 functions - one to
call thickbox and the other to call the getnews, i've been playing
with changing the javascript, but can't get it working, so i thought
i'd come back to stage 1 and see if anyone else has some ideas.
================================================== ==============
The xhtml page looks like this: It loads the AJAX related stuff in the
news.js, then the php query populates a list of hyperlinks which
presently just pop up the highslide thickbox.
================================================== ==============
<head>
<script type="text/javascript" src="java/news.js"></script>
</head>
<!--other stuff... into the php query which selects the titles of the
news articles-->
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href=\"#?article={$row['id']}\" class=\"highslide\"
onclick=\"return hs.htmlExpand(this, { contentId: 'highslide-html' } )
\">{$row['title']}</a><br>";
}
?>
================================================== ==============

news.js is this:

================================================== ==============
var xmlHttp
function getnews(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getnews.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHt tp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
================================================== ==============

and finally getnews.php is this:

================================================== ==============
$q=$_GET["q"];
$host = 'abc';
$user = 'def';
$password = 'ghi';
$db = 'jkl';
$con = mysql_connect($host, $user, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db,$con);

$sql="SELECT title, introtext FROM jos_content WHERE id = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<h1>{$row['title']}</h1>{$row['introtext']}";
}

mysql_close($con);

================================================== ==============
Everything works to a point - if I have something in the xhtml page
which feeds the ID into getnews() function then sure, the thickbox
updates with the right content (example)

Code:

<form>
<select name="test" onchange="getnews(this.value)">
<option value="1">ID 1</option>
<option value="2">ID 2</option>
<option value="3">ID 3</option>
<option value="4">ID 4</option>
</select>
</form>

but I can't figure out how to get all this running from the act of
clicking the hyperlink... the "onclick" called in the hyperlink needs
to run 2 functions - one to call thickbox and the other to call the
getnews.

Help!

Thank you
Nov 21 '08 #1
1 4416
fi****@gmail.com wrote:
Hiya,

I'm trying to get a AJAX driven update to my list of news articles, so
when users click the title of the news article, it pops up the article
content in a thickbox overlay. Retrieving content from the database
via AJAX is no problem, that works and thickbox works too, I'm just
having problems getting them both running together! It seems like it's
too much information to cram into one poor little "a href=".... the
"onclick" called in the hyperlink needs to run 2 functions - one to
call thickbox and the other to call the getnews, i've been playing
with changing the javascript, but can't get it working, so i thought
i'd come back to stage 1 and see if anyone else has some ideas.
================================================== ==============
The xhtml page looks like this: It loads the AJAX related stuff in the
news.js, then the php query populates a list of hyperlinks which
presently just pop up the highslide thickbox.
================================================== ==============
<head>
<script type="text/javascript" src="java/news.js"></script>
</head>
<!--other stuff... into the php query which selects the titles of the
news articles-->
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href=\"#?article={$row['id']}\" class=\"highslide\"
onclick=\"return hs.htmlExpand(this, { contentId: 'highslide-html' } )
\">{$row['title']}</a><br>";
}
?>
================================================== ==============

news.js is this:

================================================== ==============
var xmlHttp
function getnews(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getnews.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHt tp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
================================================== ==============

and finally getnews.php is this:

================================================== ==============
$q=$_GET["q"];
$host = 'abc';
$user = 'def';
$password = 'ghi';
$db = 'jkl';
$con = mysql_connect($host, $user, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db,$con);

$sql="SELECT title, introtext FROM jos_content WHERE id = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<h1>{$row['title']}</h1>{$row['introtext']}";
}

mysql_close($con);

================================================== ==============
Everything works to a point - if I have something in the xhtml page
which feeds the ID into getnews() function then sure, the thickbox
updates with the right content (example)

Code:

<form>
<select name="test" onchange="getnews(this.value)">
<option value="1">ID 1</option>
<option value="2">ID 2</option>
<option value="3">ID 3</option>
<option value="4">ID 4</option>
</select>
</form>

but I can't figure out how to get all this running from the act of
clicking the hyperlink... the "onclick" called in the hyperlink needs
to run 2 functions - one to call thickbox and the other to call the
getnews.

Help!

Thank you
This more properly belongs in comp.lang.javascript. If your getnews.php
correctly echoes what you want, then that is the end of the php
component of the question. If you use Firefox, then in Firebug you can
see what is returned.
Nov 21 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Bjorn | last post by:
Hi. Every time i post data in a form the contents are being checked for validity. When i click the back-button, all data is gone and i have to retype it. It's obvious that only a few or none of...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
5
by: Sanjay Pais | last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time using the with - over clauses In query analyser, the data is retrieved in under a second. When retrieving using the...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
4
by: anudu | last post by:
Hi, I am developing a system using asp.net, ajax and javascripts. I have an interface that display user details. when the user enters the Id and press search button the user details will be...
10
vikas1111
by: vikas1111 | last post by:
Hi All Can anyone give me an idea to solve the problem.. My Problem is ,, I want to Retrieving data from database and displaying in textbox... If anybody have link of some good tutorial on...
3
by: superbungalow21 | last post by:
Hey, I was wondering if it is possible to preform an action when content in the lightbox "thickbox" has completely finished rendering? So I can loop through all the elements in the thickbox.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.