We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3232
    • 380 Posts
    I just tried to use the ajaxsearch snippet be adding the basic [!AjaxSearch!] on a page.

    For some reason the ajax portion of the snippet is not working, it alwasy seems to refresh the page.

    Using the default installed snippet with modx .6.2.

    Is there anyway I can pinpoint the problem?
      • 5811
      • 1,717 Posts
      Could you read this post and tell me if it is the same thing ...

      If it is not the same issue, may be you could use the debug option to check the log.
      Here is the extract of the wiki documentation regarding the debug option:
      * 0 debug not activated

      File mode : Trace is by default logged into a file named ajaxSearch_log.txt in the ajaxSearch folder.

      * 1 : Parameters, search context and sql query logged.
      * 2 : Parameters, search context, sql query AND templates logged
      * 3 : Parameters, search context, sql query, templates AND Results logged

      To avoid an increasing of the file, only one transaction is logged. Overwritted by the log of the following one.

      FireBug mode : The trace is logged into the firebug console of Mozilla.

      * -1 : Parameters, search context and sql query logged.
      * -2 : Parameters, search context, sql query AND templates logged
      * -3 : Parameters, search context, sql query, templates AND Results logged

      with the FireBug mode you need to install: the Firebug plugin under Firefox : https://addons.mozilla.org/en-US/firefox/addon/1843 and the FirePhp plugin (version 0.2.b.1 or upper) : http://www.firephp.org/

      For the FireBug mode, Php5 is mandatory. These level -1,-2,-3 are switched respectively to 1,2,3 if your server runs whith Php4.

      For security reasons, the full name of tables (with database name) have been replaced by short names (prefix + table name only). The output produce the SELECT statement and you could use it directly by copy & paste in PhpMyAdmin to retrieve your results and undertsand it.

      Is your site living ? If yes, could you give me on this post or send by message, the address. It will be easier to search any js error
        • 3232
        • 380 Posts
        Thank you coroico for you time with this matter.

        It does not look like the same problem as in the post you described.

        I set the debug option and nothing was happening (no file was being created) so I upgraded to 1.8.1 and the debug menu started to work (but ajax still doesn’t work)

        Not sure what I am doing wrong

        debug menu output:
        [21-Nov-08 12:24:47]  AjaxSearch 1.8.1 - Php5.0.4 - MySql 4.1.20
        [21-Nov-08 12:24:47]  AjaxSearch - Configuration file default : 
        <?php
        // For a global parameter initialisation use the following syntax $__param = 'value';
        // To overwrite parameter snippet call use $param = 'value';
        
        // StripInput user function. 
        // Uncomment and complete the core function and choose your own function name
        // string functionName(string searchstring)
        // functionName : name of stripInput function passed as &stripInput parameter
        // searchstring : string php variable name as searchString input value
        // advSearch : string advSearch variable as advSearch parameter and return value
        // return the filtered searchString value
        /*
        function myStripInput($searchString, &$advSearch){
          $advSearch = 'exactphrase';
          return $searchString;
        }
        */
        // StripOutput user function
        // Uncomment and complete the core function and choose your own function name
        // string functionName(string results)
        // functionName : name of stripOutput function passed as &stripOutput parameter
        // results : string php variable name as results
        // return the filtered results
        /*
        function myStripOutput($results){ 
        
          return $results;
        }
        */
        // searchWordList user function
        // Uncomment and complete the core function and choose your own function name
        // string functionName()
        // functionName : name of searchWordList function passed as &searchWordList parameter
        // return a comma separated list of words
        /*function searchWordList($params){ 
        
          switch($params[0]){ 
            case '61':
              $list = "primary,school,education,children,teacher,africa,litteracy,bicycle";
              break;         
            case '62':
              $list = "primaire,école,éducation,enfants,professeur,afrique,littérature,bicyclette";
              break; 
          }
          return $list;
        }
        */
        ?>
        [21-Nov-08 12:24:47]  AjaxSearch - User configuration - Before parameter checking : Array
        (
            [config] => default
            [version] => 1.8.1
            [debug] => 3
            [language] => english
            [ajaxSearch] => 1
            [advSearch] => oneword
            [whereSearch] => content|tv
            [subSearch] => 5,1
            [withTvs] => 
            [order] => publishedon,pagetitle
            [rank] => pagetitle:100,extract
            [minChars] => 3
            [AS_showForm] => 1
            [resultsPage] => 0
            [grabMax] => 10
            [extract] => 1:content,description,introtext,tv_content
            [extractLength] => 200
            [extractEllips] => ...
            [extractSeparator] => <br />
            [formatDate] => d/m/y : H:i:s
            [highlightResult] => 1
            [pageLinkSeparator] =>  | 
            [AS_landing] => 
            [AS_showResults] => 1
            [idType] => parents
            [parents] => 
            [documents] => 
            [depth] => 10
            [hideMenu] => 2
            [hideLink] => 1
            [filter] => 
            [tplLayout] => @FILE:assets/snippets/ajaxSearch/templates/layout.tpl.html
            [tplResults] => @FILE:assets/snippets/ajaxSearch/templates/results.tpl.html
            [tplResult] => @FILE:assets/snippets/ajaxSearch/templates/result.tpl.html
            [tplPaging] => @FILE:assets/snippets/ajaxSearch/templates/paging.tpl.html
            [stripInput] => defaultStripInput
            [stripOutput] => defaultStripOutput
            [searchWordList] => 
            [breadcrumbs] => 0
            [tvPhx] => 0
            [clearDefault] => 0
            [jsClearDefault] => assets/snippets/ajaxSearch/js/clearDefault.js
            [ajaxSearchType] => 1
            [ajaxMax] => 6
            [showMoreResults] => 0
            [moreResultsPage] => 0
            [opacity] => 1
            [tplAjaxResults] => 
            [tplAjaxResult] => 
            [jscript] => mootools
            [addJscript] => 1
            [jsMooTools] => manager/media/script/mootools/mootools.js
            [jsJquery] => assets/snippets/ajaxSearch/js/jQuery/jquery.js
        )
        
        [21-Nov-08 12:24:47]  AjaxSearch - tplResult template @FILE:assets/snippets/ajaxSearch/templates/result.tpl.html : <div class="[+as.resultClass+]">
          <a class="[+as.resultLinkClass+]" href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
        [+as.descriptionShow:is=`1`:then=`
          <span class="[+as.descriptionClass+]">[+as.description+]</span>
        `+]
        [+as.extractShow:is=`1`:then=`
          <div class="[+as.extractClass+]"><p>[+as.extract+]</p></div>
        `+]
        [+as.breadcrumbsShow:is=`1`:then=`
          <span class="[+as.breadcrumbsClass+]">[+as.breadcrumbs+]</span>
        `+]
        </div>
        [21-Nov-08 12:24:47]  AjaxSearch - tplResults template@FILE:assets/snippets/ajaxSearch/templates/results.tpl.html : [+as.noResults:is=`1`:then=`
          <div class="[+as.noResultClass+]">
            [+as.noResultText+]
          </div>
        `:else=`
          <p class="ajaxSearch_resultsInfo">[+as.resultInfoText+]</p>
          [+as.paging+]
          [+as.listResults+]
          [+as.paging+]
        `+]
        [21-Nov-08 12:24:47]  AjaxSearch - tplResult template@FILE:assets/snippets/ajaxSearch/templates/layout.tpl.html : [+as.showForm:is=`1`:then=`
        <form [+as.formId+] action="[+as.formAction+]" method="post">
            <fieldset>
        		<input type="hidden" name="advSearch" value="[+as.advSearch+]" />
            <label for="ajaxSearch_input">
              <input id="ajaxSearch_input" class="cleardefault" type="text" name="search" value="[+as.inputValue+]"[+as.inputOptions+] />
            </label>
            <label for="ajaxSearch_submit">
              <input id="ajaxSearch_submit" type="submit" name="sub" value="[+as.submitText+]" />
            </label>
            </fieldset>
        </form>
        `+]
        [+as.showIntro:is=`1`:then=`
        <p class="ajaxSearch_intro" id="ajaxSearch_intro">[+as.introMessage+]</p>
        `+]
        [+as.showResults:is=`1`:then=`
        [+as.results+]
        `+]
        [21-Nov-08 12:24:47]  AjaxSearchPopup - User configuration - Before doSearch : Array
        (
            [config] => default
            [version] => 1.8.1
            [debug] => 3
            [language] => english
            [ajaxSearch] => 1
            [advSearch] => oneword
            [whereSearch] => content|tv
            [subSearch] => 5,1
            [withTvs] => 
            [order] => publishedon,pagetitle
            [rank] => pagetitle:100,extract
            [minChars] => 3
            [AS_showForm] => 1
            [resultsPage] => 0
            [grabMax] => 10
            [extract] => 1:content,description,introtext,tv_content
            [extractLength] => 200
            [extractEllips] => ...
            [extractSeparator] => <br />
            [formatDate] => d/m/y : H:i:s
            [highlightResult] => 1
            [pageLinkSeparator] =>  | 
            [AS_landing] => 
            [AS_showResults] => 1
            [idType] => parents
            [parents] => 
            [documents] => 
            [depth] => 10
            [hideMenu] => 2
            [hideLink] => 1
            [filter] => 
            [tplLayout] => @FILE:assets/snippets/ajaxSearch/templates/layout.tpl.html
            [tplResults] => @FILE:assets/snippets/ajaxSearch/templates/results.tpl.html
            [tplResult] => @FILE:assets/snippets/ajaxSearch/templates/result.tpl.html
            [tplPaging] => @FILE:assets/snippets/ajaxSearch/templates/paging.tpl.html
            [stripInput] => defaultStripInput
            [stripOutput] => defaultStripOutput
            [searchWordList] => 
            [breadcrumbs] => 0
            [tvPhx] => 0
            [clearDefault] => 0
            [jsClearDefault] => assets/snippets/ajaxSearch/js/clearDefault.js
            [ajaxSearchType] => 1
            [ajaxMax] => 6
            [showMoreResults] => 0
            [moreResultsPage] => 0
            [opacity] => 1
            [tplAjaxResults] => 
            [tplAjaxResult] => 
            [jscript] => mootools
            [addJscript] => 1
            [jsMooTools] => manager/media/script/mootools/mootools.js
            [jsJquery] => assets/snippets/ajaxSearch/js/jQuery/jquery.js
            [listIDs] => 
            [docgrp] => 
        )
        
        [21-Nov-08 12:24:47]  Search context main `modx_site_content` : Array
        (
            [tb_name] => `modx_site_content`
            [tb_alias] => sc
            [id] => id
            [searchable] => Array
                (
                    [0] => pagetitle
                    [1] => longtitle
                    [2] => description
                    [3] => alias
                    [4] => introtext
                    [5] => menutitle
                    [6] => content
                )
        
            [displayed] => Array
                (
                    [0] => pagetitle
                    [1] => longtitle
                    [2] => description
                    [3] => alias
                    [4] => introtext
                    [5] => menutitle
                    [6] => content
                )
        
            [date] => Array
                (
                    [0] => publishedon
                )
        
            [filters] => Array
                (
                    [0] => Array
                        (
                            [field] => published
                            [oper] => =
                            [value] => 1
                        )
        
                    [1] => Array
                        (
                            [field] => searchable
                            [oper] => =
                            [value] => 1
                        )
        
                    [2] => Array
                        (
                            [field] => deleted
                            [oper] => =
                            [value] => 0
                        )
        
                    [3] => Array
                        (
                            [field] => type
                            [oper] => =
                            [value] => 'document'
                        )
        
                    [4] => Array
                        (
                            [field] => privateweb
                            [oper] => =
                            [value] => 0
                        )
        
                )
        
            [jfilters] => Array
                (
                )
        
        )
        
        [21-Nov-08 12:24:47]  Search context joined `modx_site_tmplvar_contentvalues` : Array
        (
            [tb_name] => `modx_site_tmplvar_contentvalues`
            [tb_alias] => tv
            [id] => id
            [main] => id
            [join] => contentid
            [searchable] => Array
                (
                    [0] => value
                )
        
            [displayed] => Array
                (
                    [0] => value
                )
        
            [concat_separator] => , 
            [phx] => name, value
            [filters] => Array
                (
                )
        
            [jfilters] => Array
                (
                )
        
        )
        
        [21-Nov-08 12:24:47]  Select :  
        SELECT sc.id, sc.pagetitle, sc.longtitle, sc.description, sc.alias, sc.introtext, sc.menutitle, sc.content, sc.publishedon, 
        GROUP_CONCAT( DISTINCT CAST(ntv.id AS CHAR) SEPARATOR "," ) AS tv_id, 
        GROUP_CONCAT( DISTINCT ntv.value SEPARATOR ", " ) AS tv_value 
        FROM `modx_site_content` sc 
        LEFT JOIN( 
        SELECT DISTINCT tv.id, tv.value, tv.contentid 
        FROM `modx_site_tmplvar_contentvalues` tv 
        WHERE (((tv.value LIKE '%test%'))) ) AS ntv ON sc.id = ntv.contentid 
        WHERE ((sc.published=1) AND (sc.searchable=1) AND (sc.deleted=0) AND (sc.type='document') AND (sc.privateweb=0)) 
        GROUP BY sc.id 
        HAVING (((sc.pagetitle LIKE '%test%') OR (sc.longtitle LIKE '%test%') OR (sc.description LIKE '%test%') OR (sc.alias LIKE '%test%') OR (sc.introtext LIKE '%test%') OR (sc.menutitle LIKE '%test%') OR (sc.content LIKE '%test%') OR (tv_value LIKE '%test%'))) 
        ORDER BY sc.publishedon,sc.pagetitle
        


        Even when you use the following snippet call (for live search) the form button still appears.
        [!AjaxSearch? &ajaxSearchType=`1` &debug=`3`!]


        I’m afraid the site is not live.

          • 5811
          • 1,717 Posts
          Could you copy the select statement listed at the end of the ajaxSearch_log.txt in phpMyAdmin and check that you get the results:
          SELECT sc.id, sc.pagetitle, sc.longtitle, sc.description, sc.alias, sc.introtext, sc.menutitle, sc.content, sc.publishedon, 
          GROUP_CONCAT( DISTINCT CAST(ntv.id AS CHAR) SEPARATOR "," ) AS tv_id, 
          GROUP_CONCAT( DISTINCT ntv.value SEPARATOR ", " ) AS tv_value 
          FROM `modx_site_content` sc 
          LEFT JOIN( 
          SELECT DISTINCT tv.id, tv.value, tv.contentid 
          FROM `modx_site_tmplvar_contentvalues` tv 
          WHERE (((tv.value LIKE '%test%'))) ) AS ntv ON sc.id = ntv.contentid 
          WHERE ((sc.published=1) AND (sc.searchable=1) AND (sc.deleted=0) AND (sc.type='document') AND (sc.privateweb=0)) 
          GROUP BY sc.id 
          HAVING (((sc.pagetitle LIKE '%test%') OR (sc.longtitle LIKE '%test%') OR (sc.description LIKE '%test%') OR (sc.alias LIKE '%test%') OR (sc.introtext LIKE '%test%') OR (sc.menutitle LIKE '%test%') OR (sc.content LIKE '%test%') OR (tv_value LIKE '%test%'))) 
          ORDER BY sc.publishedon,sc.pagetitle
          If you get an issue (due to your MySql version), try to add &whereSearch=`content`. This restrict the search to the document and avoid the search in the TV (with the Group_concat statement which could generate issue with older mysql versions). With this test I would like check that the select runs normally.
            • 3232
            • 380 Posts
            ok...

            so running an sql query of:
            SELECT sc.id, sc.pagetitle, sc.longtitle, sc.description, sc.alias, sc.introtext, sc.menutitle, sc.content, sc.publishedon, 
            GROUP_CONCAT( DISTINCT CAST(ntv.id AS CHAR) SEPARATOR "," ) AS tv_id, 
            GROUP_CONCAT( DISTINCT ntv.value SEPARATOR ", " ) AS tv_value 
            FROM `modx_site_content` sc 
            LEFT JOIN( 
            SELECT DISTINCT tv.id, tv.value, tv.contentid 
            FROM `modx_site_tmplvar_contentvalues` tv 
            WHERE (((tv.value LIKE '%basil%'))) ) AS ntv ON sc.id = ntv.contentid 
            WHERE ((sc.published=1) AND (sc.searchable=1) AND (sc.deleted=0) AND (sc.type='document') AND (sc.privateweb=0)) 
            GROUP BY sc.id 
            HAVING (((sc.pagetitle LIKE '%basil%') OR (sc.longtitle LIKE '%basil%') OR (sc.description LIKE '%basil%') OR (sc.alias LIKE '%basil%') OR (sc.introtext LIKE '%basil%') OR (sc.menutitle LIKE '%basil%') OR (sc.content LIKE '%basil%') OR (tv_value LIKE '%basil%'))) 
            ORDER BY sc.publishedon,sc.pagetitle


            Returns two results (which it should)

            Some other information, The form that is being rendered on the page is:
            <form id="ajaxSearch_form"  action="simply-ming/watch-episodes/episode-search-results.htm" method="post">
                <fieldset>
            		<input type="hidden" name="advSearch" value="oneword" />
                <label for="ajaxSearch_input">
                  <input id="ajaxSearch_input" class="cleardefault" type="text" name="search" value="Search here..." onfocus="this.value=(this.value=='Search here...')? '' : this.value ;" />
                </label>
                <label for="ajaxSearch_submit">
                  <input id="ajaxSearch_submit" type="submit" name="sub" value="Go!" />
                </label>
                </fieldset>
            </form>
            <div id="ajaxSearch_output"></div>


            Now when I hit the go button, the page just refreshes in FF and goes to the homepage / in safari. It does not go to episode-search-results.htm as indicated in the action part of the form.

            very strange, I don’t get anything in the system log.

            Also when I add an idendiacal snippet call right after it, the first one will work.
            [!AjaxSearch? &AS_showResults=`0` &AS_landing=`16` &showMoreResults=`1` &moreResultsPage=`16`!]
            [!AjaxSearch? &AS_showResults=`0` &AS_landing=`16` &showMoreResults=`1` &moreResultsPage=`16`!]



              • 3232
              • 380 Posts
              I figured out the problem... i didn’t close a form that appeared earlier in the page and was throwing everything off.

                • 3232
                • 380 Posts
                coroico I have a new problem.

                I am using the getfield snippet. Every time I have the getfield snippet "get" an image tv it breaks the ajax portion of ajaxsearch.

                I know it’s not the getfield snippet itself, I have it used on other parts of the page which won’t break the ajax search. It’s only when the getfield snippet retrieves an actual image (it it’s broken it won’t break ajax)

                My ajax search call is
                [!AjaxSearch? &AS_showResults=`0` &AS_landing=`16` &showMoreResults=`1` &moreResultsPage=`16` &parents=`12` &ajaxMax=`3` &extract=`0` &depth=`4`!]


                my getfield call is
                <img src="[[GetField? &docid=`1` &field=`featured-store-image`]]" width="105" height="100" alt="[[GetField? &docid=`1` &field=`featured-store-title`]]" />


                When I have the getfield snippet outside of the image it still works
                [[GetField? &docid=`1` &field=`featured-store-image`]]


                Only when featured-store-image returns a valid image within an image tag, will it break ajax. It’s very strange. Does anyone have any ideas?

                Thanks
                Brian

                --edit--

                Turns out if I remove the width and height from the image ajax functions properly. I also use the direct resize plugin which seems to be causing the problem. If I turn off directresize or remove the height and width, ajax will function. I really need to get directresize running since it will help the loading of images much easier. I did a forum search and did not see anyone else with this problem. Does anyone know how to fix or maybe has a directresize replacement? highslide seems to be the only js config that works with ajaxsearch (everything else conflicts.)