Ajax Help needed please!!

Discussion in 'Javascript' started by inspiretechnologies@gmail.com, Sep 22, 2006.

  1. Guest

    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.
    , Sep 22, 2006
    #1
    1. Advertising

  2. ASM Guest

    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
    ASM, Sep 22, 2006
    #2
    1. Advertising

  3. Guest

    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?
    , Sep 22, 2006
    #3
  4. ASM Guest

    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 ?

    --
    ASM
    ASM, Sep 22, 2006
    #4
  5. ASM Guest

    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>

    --
    ASM
    ASM, Sep 23, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    501
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    545
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,740
    Mike Hewson
    Jan 7, 2005
  4. minnie
    Replies:
    1
    Views:
    680
    Andrew Thompson
    Dec 13, 2006
  5. shapper
    Replies:
    0
    Views:
    340
    shapper
    Dec 18, 2007
Loading...

Share This Page