AJAX: Problems returning multiple variables

Posted by fwaokda on Stack Overflow See other posts from Stack Overflow or by fwaokda
Published on 2010-12-24T23:42:24Z Indexed on 2010/12/24 23:54 UTC
Read the original article Hit count: 217

Filed under:
|
|
|

First off sorry if I'm missing something simple just started working with AJAX today. I have an issue where I'm trying to get information from my database, but different records have different amounts of values. For instance, each record has a "features" column. In the features column I store a string. (ex: Feature1~Feature2~Feature3~Feature4... ) When I'm building the object I take apart the string and store all the features into an array. Some objects can have 1 feature others can have up to whatever. So... how do I return this values back to my ajax function from my php page? Below is my ajax function that I was trying and I'll provide a link with my php file. [ next.php : http://pastebin.com/SY74jV7X ]

$("a#next").click(function()
{
    $.ajax({
           type : 'POST',
           url  : 'next.php',
           dataType : 'json',
           data     : { nextID : $("a#next").attr("rel") },
           success  : function ( data ) {

                      var lastID = $("a#next").attr("rel");
                      var originID = $("a#next").attr("rev");

                      if(lastID == 1)
                      {
                        lastID = originID;  
                      }
                      else
                      {
                        lastID--;
                      }


                      $("img#spotlight").attr("src",data.spotlightimage);
                      $("div#showcase h1").text(data.title);
                      $("div#showcase h2").text(data.subtitle);
                      $("div#showcase p").text(data.description);
                      $("a#next").attr("rel", lastID);


                      for(var i=0; i < data.size; i++)
                      {
                          $("ul#features").append("<li>").text(data.feature+i).append("</li>");
                      }

                      /*
                      for(var j=1; j < data.picsize; j++)
                      {
                          $("div.thumbnails ul").append("<li>").text(data.image+j).append("</li>");
                      }
                      */                          
           },
           error    : function ( XMLHttpRequest, textStatus, errorThrown) {
                     $("div#showcase h1").text("An error has occured: " + errorThrown);
           }
    });
});

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript