Simple jQuery Load problem

Discussion in 'jQuery' started by petschephp, Aug 27, 2010.

  1. #1
    The code I have loads a php page, but it only works if I use a button. I need it to work with a link <a href=""></a>

    <html>
    <head>
    <title>Ajax with jQuery Example</title>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/JavaScript">
    $(document).ready(function(){
    $("a").click(function(){
    $("#quote p").load("index.php");
    });
    });
    </script>
    <style type="text/css">
    #wrapper {
    width: 240px;
    height: 80px;
    margin: auto;
    padding: 10px;
    margin-top: 10px;
    border: 1px solid black;
    text-align: center;
    }
    </style>
    </head>
    <body>
    <div id="wrapper">
    <div id="quote"><p> </p></div>
    <input type="submit" id="generate" value="Generate!">
    <a href="" id="">click</a>
    </div>
    </body>
    </html>
     
    petschephp, Aug 27, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi petschephp,

    The only thing you need is to prevent default when link is clicked or simply return false:
    
    /* your code here
    ...........................
    */
    $("a").click(function(){
    $("#quote p").load("index.php");
    return false;
    });
    /* your code here
    ...........................
    */
    
    HTML:
    Regards :)
     
    koko5, Sep 1, 2010 IP