0

I have a form that is a drop down select list.

I also have an action, that looks for the request parameter:

indexAction:

if($this->getRequest()->isXmlHttpRequest())
{
  $this->setLayout('layout');
}
 $param = $this->getRequestParameter('type');

  if($param == 'video')
  {
    isicsBreadcrumbs::getInstance()->addItem('All Videos', '@homepage');
    $pager = new sfPropelPager('Item', 15);
    $pager->setPage($request->getParameter('page', 1));
    $pager->setPeerMethod('doSelectLatestVideo');
    $pager->init();
    $this->pager = $pager;
  }
  elseif($param == 'photo')
  {
    isicsBreadcrumbs::getInstance()->addItem('All Photos', '@homepage');
    $pager = new sfPropelPager('Item', 15);
    $pager->setPage($request->getParameter('page', 1));
    $pager->setPeerMethod('doSelectLatestPhoto');
    $pager->init();
    $this->pager = $pager;
  }
}

Now this works fine when the url is: example.com?type=video - it loads the video content

The problem is, I'm wanting to update the content using AJAX and because I'm doing it via AJAX, I'm struggling to get the requestParamater, since it is no longer in mu URL;

ajax function:

$("#filter-form-newsroom .submit").live('click', function(e){
$("#search-results").html(ajax_loading);
var content_type = $("#filter-form-newsroom #type").val();
$.ajax(
 {
    url: "",
    type: "GET",
    data: "?type=" + content_type,
    success: function(data){
    var $response=$(data);
    var filtered_response = $response.find('.post');
   $("#search-results").html(filtered_response).hide().fadeIn("fast");
  }
  });
 e.preventDefault();
});

This function checks the parameter in my select list and is supposed to filter by the requestParamter, but it isn't working.

Any ideas?

Thanks

1 Answer 1

2

Rather than putting ?type=" into the data property, put it in the url. Wouldn't that result in the same request you get when you type the URL yourself?

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent! I removed the data and added the ?type= to the url and works perfect!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.