Page 1 of 1

$_GET not working in AJAX?

Posted: Fri Jun 06, 2008 8:41 am
by coolin
Hi I am using AJAX & trying to work out why the following is outputing strangely:

Code: Select all

 
echo "hello world";
echo $_GET['b'];
 
This seems to output ''hello world'' correctly but even though the url seems to contain all the correct information, the value of c is shown instead of b. Also if I try to echo $_GET['c']; this seems to output nothing.

This is a Printr dump:

Code: Select all

 
[i]Array
(
    [c] => 244
    [b] => Array
        (
            [subcategories_also] => 1
            [classified_auction_search] => 0
            [search_titles] => 1
            [whole_word] => 0
            [by_zip_code] => 
            [by_zip_code_distance] => 
            [search] => Search
            [search_text] => 
            [optional_field_2] => yes
            [question_value] => Array
                (
                    [119] => 
                )
 
        )
 
    [a] => 19
    [change] => 0
)
 
[/i] 
 
In the absence of any other answer I am wondering if there is an issue with characters
Full code for function follows:

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
    function displaySearchQuestions
 
($categoryID)
    {           if ($this->debug_ajax)
        {
            
 
echo "<br>TOP OF  DISPLAYSEARCHQUESTIONS<BR>\n";
        }
        $category = 
 
$this->getCategoryQuestions($categoryID);
        $to_display = 0;
        
 
$criteria = "
                    <table cellpadding=2 cellspacing=1 border=0 
 
width=\"100%\">";
 
        // Display all optional fields
        $this->page_id = 44;
        
 
$this->get_text();
        $this->get_category_configuration($categoryID);
        $this-
 
>get_site_configuration();
        $this->get_ad_configuration();
        if(!$this-
 
>optional_fields)
            $this->CountOptionalFields();
        $field_vars = 
 
get_object_vars($this->category_configuration);
        $ad_vars = get_object_vars($this-
 
>ad_configuration_data);
        if ($i>1)
        {
            // the 
 
following is impossible to make sense of
            //if($field_vars
 
['USE_OPTIONAL_FIELD_'.$i])
            if (($field_vars['USE_OPTIONAL_FIELD_'.$i]) && 
 
(!$this->db->get_site_setting("optional_".$i."_filter_association")))
            {
        
 
        // Special case because optional field 1 has a different number than rest of 
 
scheme
                if($i == 1)
                    $criteria 
 
.="<tr>\n\t<td class=search_field_section_labels style='width:40%;'>".urldecode($this->messages
 
[1457])."</td>\n\t";
                elseif($i <= 10)
                    
 
$criteria .="<tr>\n\t<td class=search_field_section_labels style='width:40%;'>".urldecode($this
 
->messages[(1458+($i-1))])."</td>\n\t";
                elseif($i <= 20)
            
 
        $criteria .="<tr>\n\t<td class=search_field_section_labels 
 
style='width:40%;'>".urldecode($this->messages[(1933+($i-11))])."</td>\n\t";
                
 
elseif($i <= 35)
                    $criteria .="<tr>\n\t<td 
 
class=search_field_section_labels style='width:40%;'>".urldecode($this->messages[(2778+($i-
 
21))])."</td>\n\t";
                $criteria .="<td class=search_data_values>\n\t";
 
    
 
            if ($ad_vars["OPTIONAL_".$i."_NUMBER_ONLY"])
                
 
{
                    //if numbers only - produce a upper and lower limit
        
 
            $criteria .= "<table cellpadding=1 >
                        
 
<tr class=range_labels><td>".urldecode($this->messages[1440])."</td><td><input name=b
 
[by_optional_".$i."_lower] size=15 maxsize=15 class=range_labels>\n\t\t</td></tr>
            
 
            <tr class=range_labels><td>".urldecode($this->messages
 
[1441])."</td><td><input name=b[by_optional_".$i."_higher] size=15 maxsize=15 
 
class=range_labels>\n\t\t</td></tr></table>";
                }
                
 
elseif (!($ad_vars["OPTIONAL_".$i."_FIELD_TYPE"]))
                {
            
 
        //check to see if numbers only
                    if ($ad_vars
 
["OPTIONAL_".$i."_NUMBER_ONLY"])
                    {
                
 
        //if numbers only - produce a upper and lower limit
                    
 
    $criteria .= "<table cellpadding=1 >
                        <tr 
 
class=range_labels><td>".urldecode($this->messages[1440])."</td><td><input name=b
 
[by_optional_".$i."_lower] size=15 maxsize=15 class=search_data_values>\n\t\t</td></tr>
            
 
            <tr class=range_labels><td>".urldecode($this->messages
 
[1441])."</td><td><input name=b[by_optional_".$i."_higher] size=15 maxsize=15 
 
class=search_data_values>\n\t\t</td></tr></table>";
                    }
        
 
            else
                        $criteria .= "<input 
 
type=text name=b[optional_field_".$i."] id=optional_field_".$i." class=search_data_values>\n\t";
    
 
            }
                else
                {
        
 
            $query = "select * from geodesic_classifieds_sell_question_choices where 
 
type_id = ".$ad_vars["OPTIONAL_".$i."_FIELD_TYPE"]." order by display_order,value";
            
 
        if ($this->debug_ajax) echo $query."<Br>\n";
                    
 
$type_result = $this->db->Execute($query) or die();
                    if 
 
($type_result->RecordCount() > 0)
                    {
                
 
        $criteria .= "<select name=b[optional_field_".$i."] id=optional_field_".$i." 
 
class=search_data_values>";
                        $criteria .= "<option 
 
value=0></option>";
                        $matched = 0;
                
 
        while ($show_dropdown = $type_result->FetchRow())
                    
 
    {
                            $criteria .= "<option 
 
value=\"".$show_dropdown['value']."\" ";
                            
 
if ($this->classified_variables["optional_field_".$i] == $show_dropdown['value'])
            
 
                {
                                
 
$criteria .= "selected";
                                $matched 
 
= 1;
                            }
                        
 
    $criteria .= ">".$show_dropdown['value']."</option>\n\t\t";
                    
 
    }
                        $criteria .= "</select>";
            
 
        }
                    else
                    
 
//blank text box
                    $criteria .= "<input type=text name=b
 
[optional_field_".$i."] id=optional_field_".$i." class=search_data_values>\n\t";
            
 
    }
                if (($ad_vars["OPTIONAL_".$i."_OTHER_BOX"]) && 
 
($ad_vars["OPTIONAL_".$i."_FIELD_TYPE"]))
                    $criteria .= " 
 
".urldecode($this->messages[1458])." <input type=text name=b[optional_field_".$i."_other] 
 
class=search_data_values>\n\t";
                $criteria .="</td>\n</tr>\n";
            
 
    $to_display++;
            }
            elseif ($this->db-
 
>get_site_setting("optional_".$i."_filter_association"))
            {
            
 
    //replace this
                //$criteria .= "associated with filter";
        
 
    }
        }
 
        //spit out the questions
        if(is_array
 
($category))
        {
            foreach ($category["questions"] as $key => 
 
$value)
            {
                //get the list of choices for this 
 
question
                if ($category["choices"][$key] == "check")
            
 
    {
                    $criteria .= "
                        
 
    
                                <span 
 
class=search_field_section_labels style='width:10%;'>".$category["questions"][$key]."</span>
        
 
                                                    
 
        <input class=search_data_values type=checkbox name=b[question_value][".$key."] 
 
value=\"".$category["questions"][$key]."\">
                                
 
                            ";
                    
 
$to_display++;
                }
                elseif ($category
 
["choices"][$key] == "none")
                {
                    
 
$criteria .= "
                            <tr>
                    
 
            <td class=search_field_section_labels style='width:40%;'>".$category
 
["questions"][$key]."</td>
                                <td 
 
class=search_data_values>
                                    
 
<input class=search_data_values type=text name=b[question_value][".$key."] />
                
 
                </td>
                            </tr>";
        
 
            $to_display++;
                }
                
 
elseif ($category["choices"][$key] == "url")
                {
                
 
    $criteria .= "
                            <tr>
                
 
                <td class=search_field_section_labels 
 
style='width:40%;'>".$category["questions"][$key]."</td>
                        
 
        <td class=search_data_values>
                                
 
    <input type=text name=b[question_value][".$key."] />
                        
 
        </td>
                            </tr>";
                
 
    $to_display++;
                }
                elseif 
 
($category["choices"][$key] == "textarea")
                {
                
 
    //FOR THE SEARCH FORM ALL TEXT AREA BOXES ARE TO DISLPAYED AS REGULAR TEXT BOXES
        
 
            $criteria .= "
                            
        
 
                        <span class=search_field_section_labels 
 
style='width:40%;'>".$category["questions"][$key]."</span>
                        
 
        <span class=search_data_values>
                                
 
    <input type=text name=b[question_value][".$key."] />
                        
 
        </span>
                            ";
                
 
    $to_display++;
                }
                elseif 
 
($category["choices"][$key] != "none")
                {
                    
 
$query = "select * from geodesic_classifieds_sell_question_choices where type_id = '{$category
 
["choices"][$key]}' order by display_order,value";
                    if 
 
($this->debug_ajax) echo $query."<Br>\n";
                    $result = $this
 
->db->Execute($query) or die("An error has occurred ".__LINE__);
 
                    
 
if ($result->RecordCount() > 0)
                    {
 
                    
 
    $criteria .= "                      
                    
 
            &nbsp;{$category["questions"][$key]}
                        
 
        
                                    <select 
 
name=b[question_value][$key] class=search_data_values>
                            
 
            <option></option>";
                        while 
 
($row = $result->FetchRow())
                            
 
 
echo "hello world";
echo $_GET['b'];
if($_GET['b']['question_value'][$key]==$row["value"]){$criteria .="<option selected>{$row
 
["value"]}</option>";}
 
else{
$criteria .= "
                                        
 
<option>{$row["value"]}</option>";
}                       $criteria .= "
        
 
                            </select>
                    
 
            
                            ";
            
 
            $to_display++;
                    }
                
 
}
            }
        }
        $criteria .= "
                    
 
</table>";
        //set header for charset, otherwise questions don't show up right for 
 
weird charsets..
        $charset = geoString::getCharsetTo();
        if (!$charset){
        
 
    //if not using charsetTo, then use the charsetclean setting.
            $charset 
 
= geoString::getCharset();
        }
        
        header('Content-Type: 
 
application/x-javascript; charset='.$charset);
        echo ($to_display == 0) ? 
 
"&nbsp;|catQuestions" : "$criteria|catQuestions";
 
        exit;
    }
 
//%%%%%%%%%%%%%%%%%%%%
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
   


Any help appreciated

Re: $_GET not working in AJAX?

Posted: Fri Jun 06, 2008 8:48 am
by vargadanis
What is the output if you use $_GET['b']['optional_field_2'] ?

Please put the dump of print_r in code tags as well. It will keep it's indention.

Re: $_GET not working in AJAX?

Posted: Fri Jun 06, 2008 1:29 pm
by dbemowsk
Show us the URL that you used to get those print_r results. I am assuming that is the print_r of the $_GET and not the $_REQUEST.

Re: $_GET not working in AJAX?

Posted: Fri Jun 06, 2008 7:48 pm
by coolin
Thanks, yes I used GET not REQUEST for the print_r. I tried using $_GET['b']['optional_field_2'];
this gave an output of the number 2 and the following print_r dump

Code: Select all

Array
(
    [c] => 244
    [b] => Array
        (
            [subcategories_also] => 1
            [classified_auction_search] => 0
            [search_titles] => 1
            [whole_word] => 0
            [by_zip_code] => 
            [by_zip_code_distance] => 
            [search] => Search
            [search_text] => 
            [optional_field_2] => yes
            [question_value] => Array
                (
                    [119] => 
                )
 
        )
 
    [a] => 19
    [change] => 0
)
 
This was from the url-

Web address... /index.php?c=244&b%5Bsubcategories_also%5D=1&b%5Bclassified_auction_search%5D=0&b%5Bsearch_titles%5D=1&b%5Bwhole_word%5D=0&b%5Bby_zip_code%5D=&b%5Bby_zip_code_distance%5D=&a=19&change=0&b%5Bsearch%5D=Search&b%5Bsearch_text%5D=&b%5Boptional_field_2%5D=yes&b%5Bquestion_value%5D%5B119%5D=

Re: $_GET not working in AJAX?

Posted: Tue Jun 10, 2008 8:19 am
by coolin
Just found out the number 2 may be some form of syntax/error code (sometimes also appears as a 3)

Re: $_GET not working in AJAX?

Posted: Sun Jun 15, 2008 7:25 pm
by coolin
Just tried using a print_r dump to directly replace echo "hello world" & this gives:

Code: Select all

Array
(
    [a] => ajax
    [action] => displaySearchQuestions
    [b] => 244
)