Ajax Help needed please!!

  • Thread starter inspiretechnologies
  • Start date
I

inspiretechnologies

Hi all,

I'm creating a Php page with connection to a MySql database. In this
page, I get all the articles (text) of a member, and when the article's
length exceeds 500 characters, a link "read more" is shown. I must
implement with Ajax a function that allows, when the link "read more"
is clicked, to show the rest of the article. It's a sort of slide down
function but more complicated I think. I'm a beginner so please can
someone help me with some ideas.

Thanks.
 
A

ASM

(e-mail address removed) a écrit :
Hi all,

I'm creating a Php page with connection to a MySql database. In this
page, I get all the articles (text) of a member, and when the article's
length exceeds 500 characters, a link "read more" is shown.

and what is the href of this link ?

and what is it supposed to happen when link is pressed (without AjaX) ?
I must
implement with Ajax a function that allows, when the link "read more"
is clicked, to show the rest of the article. It's a sort of slide down
function but more complicated I think. I'm a beginner so please can
someone help me with some ideas.

I suppose you need to call the href of your link through an XMLHttpRequest

<a href="more.php?article=245"
onclick="myAjaXRequest(this.href); return false;">
read more
</a>

What is it :
http://en.wikipedia.org/wiki/XMLHttpRequest
Simple example step by step :
http://www.webpasties.com/xmlHttpRequest/
And some more ... :
http://www.ajaxtoolbox.com/
http://ajaxpatterns.org/Ajax_Examples
 
I

inspiretechnologies

On click on this href, we'll see the entire article.
In fact, when the link "read more" is clicked, we'll have like an
extension of the existing article.

example :

Today, there are too many wars in the worl...
"Read More"


If we click on "Read More" we'll obtain this result :

Today, there too many wars in the world. This is caused by etc etc.

I must have that by an Ajax Function, such as Slide_Down(), seen in
scriptaculos.us
Notice that the article is extracted from the database.

Thanks for your interest.

Ps: Is there any possibility of not using the XmlHttpRequest?
 
A

ASM

(e-mail address removed) a écrit :
On click on this href, we'll see the entire article.

I undertood :)
But that doesn't tell how it works (in "normal" mode).
I mean : what the link calls ?
In fact, when the link "read more" is clicked, we'll have like an
extension of the existing article.

Certainly, but that doesn't come by operation of the holy spirit ?
In what I call "normal" mode, the php is doing something : call to MySql
for the complete article and write it in correct place in html code then
send back the entire page completed.
I must have that by an Ajax Function, such as Slide_Down(), seen in
scriptaculos.us

Sorry ... don't know what about you talk.
Notice that the article is extracted from the database.

Thanks for your interest.

Ps: Is there any possibility of not using the XmlHttpRequest?

XmlHttpRequest is part of AjaX ... !
Didn't you ask to work with AjaX ?

I'm afraid your "red more" doesn't work even in "normal" way ?
 
A

ASM

(e-mail address removed) a écrit :
Ps: Is there any possibility of not using the XmlHttpRequest?

In JavaScript You can have in your page your entire article truncated :

<p class="article">
Today, there are too many wars in the world
<span>...<br>
<cite>
<a href="complete.php" onclick="readMore(this); return false;">
"Read More"
</a>
</cite>
</span>
<span class="less">
.<br>
This is caused by :<br>
etc <br>
etc.<br>
<cite>
<a href="complete.php" onclick="readMore(this); return false;">
"Read Less"
</a>
</cite>
</span>
</p>


and in header :

<style type="text/css">
p.article span { display: inline; }
p.article span.less { display: none; }
p.article_all span { display: none; }
p.article_all span.less { display: inline; }
p cite { margin-left: 70%; }
</style>
<script type="text/javascript">
function readMore(what) {
what = what.parentNode.parentNode.parentNode;
what.className = what.className=='article'? 'article_all' : 'article';
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top