1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to post value without refresh page with jquery $post?

Discussion in 'PHP' started by youlichika, Nov 2, 2010.

  1. #1
    How to post value without refresh page with jquery $post? Click test1 ,show test1 in div2, click test2,clear div2 and show test2. Thanks.


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
    $.post('index.php',{"id":"div1","name":"post"});
    </script>
    <div id="div1">
    <ul>
    <li>
    <a href="index.php" name="post">test1</a>
    </li>
    <li>
    <a href="index.php" name="post">test2</a>
    </li>
    </ul>
    </div>
    <div id="div2">
    this is a <? $_POST["name"]; ?>, just a test.
    </div>
    HTML:
     
    youlichika, Nov 2, 2010 IP
  2. GNi33

    GNi33 Peon

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could make an .ajax() or .post() call to an .php - file, which returns the result (as a div for example). In the .ajax()-function there is an attribute success.
    With this attribute you can define a function that is called after the ajax-call has finished:

    
    $.ajax({
        type: "POST",
        url: "submit.php",
        data: submitData,
        dataType: "html",
        success: function(msg){
      }
    });
    
    Code (markup):
    now you can access the data that you returned in the "submit.php" file over the "msg"-variable in jquery and add it to the div you want to.

    But I don't know if there is a way to access the $_POST - values like you tried to do...
     
    GNi33, Nov 2, 2010 IP