June 8, 2010

jquery/ajax post() in a posted page

Question by haltman

I have a page with a div, inside this div I load a page with a form with a select, I can get selected option by post() function but, how can I get at the same time selected option and full data option? I’ve tried to get full data with a post() in a click() function positioned directly on form page but it does not work, can I post 2 times on the same page(one for get selected option and one for full data option)?

thanks in advance

ciao,
h.

Answer by AdmSteck

I would use post to get all the options and then in the success function make another ajax post call to get the selected option. This way you can ensure all the options are loaded before trying to set the selected option.

Answer by Starx

If you are trying to load different portion on a page you can try this

  1. Create a page with all the contents you want to load, and seperate the contents with a switch for example “content.php”

    <?
    $key = $_POST['key'];
    switch($key) {
             case "news":
                  echo '<div id="news">.............News Content.............</div>';
                  break;
             case "link":
                  echo '<ul> 
                            <li> <a href="home.html">Home</a> </li> 
                            <li> <a href="aboutus.html">About us</a> </li> 
                        </ul>';
                  break;
             default:
                  echo "Sorry, the content is not available.";
                  break;
    }
    ?> 
    

Then afterwards in the page where you make calls do something like this

$(document).ready(function() {
     $("#menudiv").load("content.php", { key: 'link' });
     $("#newsdiv").load("content.php", { key: 'news' });

 });

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!