5 Replies Latest reply on Jun 5, 2014 10:30 PM by PerryMac

    Ajax does not seem to work

    PerryMac

      Hi,

       

      Can't seem to load any data from my php page into my edge animate.

       

      Here is my code:

       

      .ajax({ url: 'http://server-x:7890/db.php',

        dataType: 'json',

        success: function(data)

        { sym.$("Output1").html(data);

        }

      });

       

      so I tried to debug it by changing it to

      .ajax({ url: 'http://server-x:7890/db.php',

        dataType: 'json',

        success: function(data)

        { sym.$("Output1").html("Help");

        }

      });

      And getting nothing. I can write successfully with sym.$("Output1").html("Help") outside Ajax function.

       

      My db.php works successfully and  returns

      "Ajax." -- in my crome browser

       

      Anyone know what could be wrong?

        • 1. Re: Ajax does not seem to work
          joel_pau Level 5

          Hi,

           

          What is the return of console.log(data)? success: function(data){ console.log(data) }

           

          Have you checked your json? http://jsonlint.com

           

          From this page, here is a demo file: https://app.box.com/s/najery8nbgy7mcdbam0q

          1 person found this helpful
          • 2. Re: Ajax does not seem to work
            PerryMac Level 1

            Any chance you can help me with this part too? "success: function(data){ console.log(data) }"

            I read this but could not get to work.

             

            The demo file works and displays the 12 items. Trying to merge it into my code with no luck yet.

             

            Thanks so much for the help.

            • 3. Re: Ajax does not seem to work
              PerryMac Level 1

              Fixed issues with JSON using jsonlint, thanks

              trying to use example with flickr and my data to get something to display in edge with no luck either

              • 4. Re: Re: Ajax does not seem to work
                joel_pau Level 5

                Here is how to read console.log(data) using my new demo file.

                consoleData.jpg

                This first pic shows that items are within an array. I have to browse this array. So, i will use a loop. For instance: $.each()

                I will write: $.each( data.items, function(index,value){...}

                I open items (picture above).

                consoleDataArray.jpg

                This array contains 20 objects from 0 to 19. I look to items[0], i see that it contains an object named « media ».

                Above, i can finally see where is located a picture.

                consoleDataArrayMedia.jpg

                Get a picture, i have to browse items array and return the value of .media.m

                Get a link: value.link

                Get a title: value.title

                function(data) {

                  console.log("data returns the entire json:",data);

                  //console.log("data.items returns an array of 20 objects:",data.items);

                  $.each( data.items, function(index,value){

                  var cell = sym.createChildSymbol("slide", "container");

                  cell.getSymbolElement().css("display", "inline-block");

                  cell.$("photo").css("background-image", "url("+value.media.m+")");

                  cell.$("title").html(value.title);

                  if ( index == 11 ) return false; //only 12 items on Stage. FlickR API returns 20 items by default.

                  } );//each is completed.

                 

                 

                 

                You can also use your assets box (picture above) and open the json file.

                [] means an array.

                {} means an object.

                consoleSafari.jpg



                1 person found this helpful
                • 5. Re: Re: Ajax does not seem to work
                  PerryMac Level 1

                  I was missing something to view the logs so I installed Firefox and Firebug.

                  Then I saw the data was being block by Cross Domain Issue.

                   

                  Added this to my php file then I could read the arrays successfully

                  <?php

                  header("Access-Control-Allow-Origin: *");

                   

                  Final issue, I am now getting

                  "TypeError: e is undefined

                   

                   

                  ...==t}},CLASS:function(e){var t=C[e+" "];return t||(t=RegExp("(^|"+M+")"+e+"("+M+"...

                  jquery....min.js (line 4

                  using jquery 2.0.3.min.js

                   

                  thanks in advance