0

I have two .phtml files in magento, one which is used in the home cms page and is referenced like this:

{{block type="catalog/product_list" category_id="11" template="catalog/product/special-products.phtml"}}

then I wish to ajax;

<script>
function loadXMLDoc(pageNo)
{
var xmlhttp;
if (pageNo.length==0)
  { 
  document.getElementById("productsDiv").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {

  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("productsDiv").innerHTML=xmlhttp.responseText;
    }
  }

xmlhttp.open("GET","special-products-ajax.phtml?page_number="+pageNo,true);
xmlhttp.send();
}
</script>

<script>
//call after page loaded
window.onload = loadXMLDoc("1"); 
</script>

within this file (special-products.phtml) to access special-products-ajax.phtml which I've put in the same directory however the xmlhttp.status is returning as 404 (not found). I tried moving this file to a folder in the root directory "/scripts", the ajax worked but I didnt have any access to the Mage app. Please help me Im really stuck on this one.

Kevin
  • 41,694
  • 12
  • 53
  • 70
davidelias16
  • 91
  • 1
  • 10
  • You need to send ajax request to a controller. phtml files are template files and can't be accessed directly. – subroutines Sep 23 '14 at 04:35
  • You need to create a custom module with at least one controller wich one is going to manage the request and deliver the respond.Also, use jquey.ajax in order to make everything easier. – Beto Castillo Sep 23 '14 at 05:35
  • Do you know of any very simple, easy, straightforward tutorials for creating and implementing a new custom module in magento? – davidelias16 Sep 23 '14 at 05:51

0 Answers0