SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Manchester
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Response is null when calling $.getJSON on a remote server

    I have a drop down menu with a change event that makes a JQuery JSON AJAX request, which I've simplified for this post:

    Code JavaScript:
     
    $('#id_template').change( function() {
     
        var data = {
     
            action: 'change_template'
     
        };
     
        $.getJSON( '/ajax/index.php/section/', data, function( response, status ) {
     
            if( status == 'success' ) {
     
                $('#id_parent_section').html( response.id_parent_section );                                                        
     
            }        
     
        });                        
     
        return false;
     
    });

    This AJAX request calls the following PHP function (simplified too):

    PHP Code:

        
    protected function change_template() {
            
            
    $this->response['id_parent_section'] = 'yes';
                           
            echo 
    json_encode$this->response );
            
        } 
    When I do change the drop menu's value, the request seems to be successfully sent with a successful reply received (inspected it in Firebug), as the content in the "status == success" is accessed. However, the problem is the response is null.

    I don't have this problem when I'm testing on my local WAMP setup, and so have no idea why everything appears to be working fine here except the retrieval of the response array.

    Any help is much appreciated.

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Manchester
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, noticed that my server's PHP version is 5.1.6 and it was only until PHP 5.2 when the json_encode function was added. I'm hoping this explains the problem I've been having.


Bookmarks

Posting Permissions

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