Support » Fixing WordPress » Using ajax with shortcode

  • Heres an easy for you all!
    I want to use next gen gallery using ajax to load the shortcode of my page. I use some links inside the page so than when i click them to load the new next gen shortcode without reloading the page.

    Things i have done:
    1. I have added the following shortcode in the body of my webpage:

    <div id="gallery"><?php echo do_shortcode("[slideshow id=1 w=800 h=100]"); ?></div>

    2.Inside a page i have added the following links:

    <a href="#" onClick="show(1);" id="gallery">Click to show Gallery 1</a>
    <a href="#" onClick="show(2);" id="gallery">Click to show Gallery 2</a>

    3.The ajaxcode:

    <script type="text/javascript">
    // var site = $site;
    function show(num){
    	var gallery_id = num;
    	var xmlhttp;
    	if (window.XMLHttpRequest)
    	  {// code for IE7+, Firefox, Chrome, Opera, Safari
    	  xmlhttp=new XMLHttpRequest();
    	  {// code for IE6, IE5
    	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	xmlhttp.send("gallery=" + gallery_id);

    4.The ajax info file contains the following:

    <?php echo do_shortcode("[slideshow id=".$_POST['gallery']." w=800 h=100]"); ?>

    But i get a php error that the shortcode is not recognised.
    Any solution/ideas for fixing that?? Or any other approach??

    Thank you in advance!

  • The topic ‘Using ajax with shortcode’ is closed to new replies.