Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts

    AJAX Request: Not properly retrieving data

    Am I missing something? I get the alert stating that the function has indeed been called but apparently the rest is not successful . . . I don't get an alert with the json data in it.

    PHP Code:
            function updateCreatureList() {
                
    alert('called');
                $.
    ajax({
                    
    type'GET',
                    
    url'scripts/php/process.php?mode=creatureList',
                    
    dataType'json',
                    
    success: function(data){
                        
    alert(data);
                    }
                });
            } 
    here is the php in process.php if it matters
    PHP Code:
        if ($_GET['mode'] == 'creatureList') {
            
    $query "SELECT * FROM `creatures`";
            
    $result mysql_query($query$link) or die(mysql_error());
            
    $row mysql_fetch_array($result);

            echo 
    json_encode($row);
        } 

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 725 Times in 719 Posts
    The best way to debug this sort of thing is to view the messages generated in the console (e.g Firebug's).

    You should be able to see the ajax call going out with the parameters and then the response from your php file.

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Have you attached the jQuery library?
    Is your page in the same location as the 'scripts' sub-folder?
    Has $link been established?

    Type '..process.php?mode=creatureList' in the address bar to test it.
    Last edited by AndrewGSW; 12-15-2012 at 01:23 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    New Coder
    Join Date
    Jul 2005
    Posts
    92
    Thanks
    4
    Thanked 0 Times in 0 Posts
    lol yes, the jquery library has been attached and is used for a majority of my page. I'm not exactly sure what you mean by: "Is your page in the same location as the 'scripts' sub-folder?" but process is successfully called by other functions using the .post() command to put data IN the database and $link is definitely set.

    When I access the page, I get a json encoded array echo'd from the database. The issue is that it's not being retrieved by the .ajax() function.

    I tried using:
    PHP Code:
                $.getJSON('scripts/php/process.php?mode=creatureList', function(data) {
                    
    alert(data);
                }); 
    That returns an object though. At least something is being returned!

    -EDIT-
    Wasn't thinking about the fact that you can only alert a string. I sent it to the console and I'm getting the data back properly. Thanks for the help.
    Last edited by Styles2304; 12-15-2012 at 02:23 PM. Reason: Update

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    lol yes, the jquery library has been attached
    He, he! You'd be surprised how often..
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •