473,238 Members | 2,740 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,238 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 4412
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.
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.