Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2012, 05:09 AM   PM User | #1
Styles2304
New Coder

 
Join Date: Jul 2005
Posts: 84
Thanks: 4
Thanked 0 Times in 0 Posts
Styles2304 is an unknown quantity at this point
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);
    } 
Styles2304 is offline   Reply With Quote
Old 12-15-2012, 11:38 AM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
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.
SB65 is offline   Reply With Quote
Old 12-15-2012, 01:21 PM   PM User | #3
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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.
__________________
"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

Last edited by AndrewGSW; 12-15-2012 at 01:23 PM..
AndrewGSW is offline   Reply With Quote
Old 12-15-2012, 02:09 PM   PM User | #4
Styles2304
New Coder

 
Join Date: Jul 2005
Posts: 84
Thanks: 4
Thanked 0 Times in 0 Posts
Styles2304 is an unknown quantity at this point
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
Styles2304 is offline   Reply With Quote
Old 12-15-2012, 02:27 PM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
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
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:28 PM.


Advertisement
Log in to turn off these ads.