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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    62
    Thanks
    9
    Thanked 0 Times in 0 Posts

    read php array using Jquery

    I have a php array in a page suggest.php:
    PHP Code:
        while($row mysql_fetch_assoc($query))
            {
                
    $res[] = $row['keyword'];
                
            }
                return 
    $res
    i have a jquery script in index.php:
    PHP Code:
    $.ajax({
                        
    type:"GET",
                        
    url:"incs/search.php",
                        
    data"keywords=" data "&submit=Find",
                        
    success:function(html){
                            
    //this is where i'd like to make the array from $res
                        
    }
                        
                    }); 
    Basically i send a request to suggest.php via jquery ajax,and i get an answer,that is $res.The problem is that i can't figure out how to make a jquery array form $res. I tried :
    PHP Code:
    var hits = $.makeArray(html); 
    ,and a few other things,but none of them worked.
    Please help me.

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    Easier to let PHP convert the array into JSON before returning I think, using json_encode.

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    62
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I tried your idea,but all i get is a string,something like:
    PHP Code:
    ["temperature","temperature","temperatures","attempts"

  • #4
    New Coder
    Join Date
    Nov 2009
    Posts
    62
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Ok,i've found a way:
    PHP Code:
    var hits = $.parseJSON(html); 
    works for me.Is it proper usage of this function?


  •  

    Posting Permissions

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