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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    jquery ajax with get

    I have the following function:
    Code:
    ...
          $.ajax({
            type: "POST",
            url: showresults.php,
            data: "clickedPage=" + clickedPage + "&id=" + id, 
            error: function(){        
                alert('Error loading XML document');                    
            },
            success: function(msg){                        
            //put results received from ajax call to div                      
            }
          });  
    ...
    Then I have in showresults.php lines
    Code:
    if(!empty($_POST[clickedPage])){
        $clickedPage=$_POST[clickedPage];
      }

    Everything is fine, but I don't know how I can use this with GET. I tried to replace type: "POST", with type: "GET", and then if(!empty($_GET[clickedPage])){... but it doesn't work.

    What would be the correct syntax in function to get in showresults.php data with GET?

    Thanks a lot

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I wouldn't do data: "clickedPage=" + clickedPage + "&id=" + id,
    , I would do

    PHP Code:
    data: {"clickedPage" clickedPage"id" id
    Also if I may nitpick for a moment, you should be enclosing your array index names in quotes, it's bad form to not.

    PHP Code:
    if(!empty($_GET['clickedPage'])){
        
    $clickedPage=$_GET['clickedPage'];
      } 


  •  

    Posting Permissions

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