I would like to call the catalog/layer/view.phtml file via ajax.
There is absolutely no change in the code, everything is same but just want to call the view.phtml in ajax.
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
I am going to use the following jquery code.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#showsearch").load("/app/design/frontend/default/mytheme/template/catalog/layer/test.phtml", function(response, status, xhr) { alert(response);
});
});
</script>
<div id="showsearch"></div>
I was placing the jquery code in view.phtml but it returns 404 error.
Am I doing something which is completely impossible or it can be done in some other way?
Using JavaScript you can only .load()
URLs that you would normally type in your browser's address bar (since JS is client-side). You cannot use absolute file paths of your server this way.
To load this file, you have basically the following options:
DocumentRoot
(i.e. most likely where your index.php
file is, often public_html
or www
)<?php include($yourAbsolutePath); ?>
Since you want to use AJAX to load the file, the best thing you could do is .load()
a PHP file that is above your DocumentRoot
and include()
the file from there.
Example
DocumentRoot
(e.g. myFile.php)Put the following myFile.php:
<?php include('/app/design/frontend/default/mytheme/template/catalog/layer/test.phtml'); ?>
Change your .load()
line to:
$("#showsearch").load("/myFile.php", function(response, status, xhr) { ...