CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   jQuery AJAX Request: Not properly retrieving data (http://www.codingforums.com/showthread.php?t=284171)

Styles2304 12-15-2012 05:09 AM

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);
    } 


SB65 12-15-2012 11:38 AM

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.

AndrewGSW 12-15-2012 01:21 PM

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.

Styles2304 12-15-2012 02:09 PM

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.

AndrewGSW 12-15-2012 02:27 PM

Quote:

lol yes, the jquery library has been attached
He, he! You'd be surprised how often.. :rolleyes:


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

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.