Hi there!
I’m making a simple ajax call using jquery to a custom module. The jQuery is like so:
var text = 'text';
var orderby = 'order';
var source = 'source';
var media = 'media';
var tags = 'tags';
var fetchUrl = '/search/results/ ' + text + '/' + orderby + '/' + source + '/' + media + '/' + format + '/' + tags;
$.ajax({
type: "POST",
url: fetchUrl,
cache: false,
data: "after=000000",
success: function(data){
searchResults.html(data);
$('#results').masonry({
columnWidth: 360,
itemSelector: '.related'
});
}
});That’s calling the template search/results.html:
{exp:aq_resources:search text="{segment_3}" orderby="{segment_4}" source="{segment_5}" media="{segment_6}" format="{segment_7}" tags="{segment_8}"}Then the search function in aq_resources (the TMPL library is being loaded in the parent class):
function search()
{
$output = '';
$text = $this->EE->TMPL->fetch_param('text');
$orderby = $this->EE->TMPL->fetch_param('orderby');
$source = $this->EE->TMPL->fetch_param('source');
$media = $this->EE->TMPL->fetch_param('media');
$format = $this->EE->TMPL->fetch_param('format');
$tags = $this->EE->TMPL->fetch_param('tags');
$output .= $text . $orderby;
return $output;
}All of the TMPL->fetch_params are returning blank values. Anyone got any ideas as to why it might not be working?
Thanks!
James
Hey James,
A few things I’d try:
Hi Erik,
Thanks very much for getting back to me. I tried hitting /search/results/text/orderby/source/media/format/tags directly as suggested and am still getting a blank result, so it looks as though there’s a problem with getting values through the fetch_param() function to the plugin.
I’ve also tried creating a new reference to the EE_Tmpl library like so:
$TMPL = new EE_Template;
$text = $TMPL->fetch_param('text');
$orderby = $TMPL->fetch_param('orderby');
// etc....With no success. Can you think of any reason why the values might not be getting passed through fetch_param()?
Thanks again!
James
P.s. - Thanks for the info on the Template Logger, very useful!
Can you think of any reason why the values might not be getting passed through fetch_param()?
My first guess is that the values getting passed are empty strings. Try this:
• Create a new template that only contains your plugin tag • Add your tag in to include just one of those parameters (try ‘text’ for example) • Update your search() method to start with the following code:
<?php
public function search()
{
exit(var_dump($this->EE->TMPL->fetch_param('text')));Then load your template and see what spits out. If that shows your expected value of ‘text’ then it’s probably an issue with the way your jQuery request is working with your template.
It looks as though there was something in the parent class which was affecting the template values getting through (there was a fair bit of cruft in there which must have been causing problems). I’ve now made a new plugin which is returning the values fine, however they aren’t coming back through the ajax request which means something’s amis with my jQuery.
Any ideas gratefully received, otherwise will push on and post back with updates.
Ok, so I’m able to get the proper values returned when I hit /search/results/text/orderby/source/media/format/tags via ajax with static text in the tags. For example:
{exp:aq_search text="test string" orderby="test string" source="test string" media="test string" format="test string" tags="test string"}returns the test strings just fine. However when I try:
{exp:aq_search text="{segment_3}" orderby="{segment_4}" source="{segment_5}" media="{segment_6}" format="{segment_7}" tags="{segment_8}"}None of the strings are passed through to the plugin. So long story short the segment vars seem to be being populated properly when I visit the page directly, but not at all when I hit it with ajax.
Does anyone have any ideas about why this could be happening? I’m thinking something to do with parse order?
Thanks
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.